Search is not available for this dataset
name
stringlengths 2
112
| description
stringlengths 29
13k
| source
int64 1
7
| difficulty
int64 0
25
| solution
stringlengths 7
983k
| language
stringclasses 4
values |
---|---|---|---|---|---|
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | # Codeforces Round #426 (Div. 2)
# 834A
class Node:
def __init__(self,data):
self.data = data;
self.next = None;
self.prev = None;
class CreateList:
# initialize head and tail to null
def __init__(self):
self.head = Node(None);
self.tail = Node(None);
self.head.next = self.tail;
self.head.prev = self.tail
self.tail.next = self.head;
self.tail.prev = self.head
#Add node
def add(self,data):
newNode = Node(data);
if self.head.data is None:
#if list empty, set newnode to head and tail
self.head = newNode;
self.tail = newNode;
newNode.next = self.head;
newNode.prev = self.tail
else:
self.tail.next = newNode;
newNode.prev = self.tail
self.tail = newNode;
self.tail.next = self.head;
self.head.prev = self.tail
cl = CreateList();
cl.add('^');
cl.add('>');
cl.add('v');
cl.add('<');
in1 = input().split()
pStart = in1[0]
pEnd = in1[1]
n = int(input())
if n > 4:
n = n%4
cur = cl.head
for i in range(4):
if cur.data == pStart:
cur = cur
break
else:
cur = cur.next
start = cur
cw = False
ccw = False
for i in range(n):
cur = cur.next
if cur.data == pEnd:
cw = True
cur = start
for i in range(n):
cur = cur.prev
if cur.data == pEnd:
ccw = True
if cw and not ccw:
print("cw")
elif ccw and not cw:
print("ccw")
else:
print("undefined") | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
template <typename T, typename T1>
ostream &operator<<(ostream &out, pair<T, T1> obj) {
out << "(" << obj.first << "," << obj.second << ")";
return out;
}
template <typename T, typename T1>
ostream &operator<<(ostream &out, map<T, T1> cont) {
typename map<T, T1>::const_iterator itr = cont.begin();
typename map<T, T1>::const_iterator ends = cont.end();
for (; itr != ends; ++itr) out << *itr << " ";
out << endl;
return out;
}
template <typename T>
ostream &operator<<(ostream &out, set<T> cont) {
typename set<T>::const_iterator itr = cont.begin();
typename set<T>::const_iterator ends = cont.end();
for (; itr != ends; ++itr) out << *itr << " ";
out << endl;
return out;
}
template <typename T>
ostream &operator<<(ostream &out, multiset<T> cont) {
typename multiset<T>::const_iterator itr = cont.begin();
typename multiset<T>::const_iterator ends = cont.end();
for (; itr != ends; ++itr) out << *itr << " ";
out << endl;
return out;
}
template <typename T,
template <typename ELEM, typename ALLOC = allocator<ELEM>> class CONT>
ostream &operator<<(ostream &out, CONT<T> cont) {
typename CONT<T>::const_iterator itr = cont.begin();
typename CONT<T>::const_iterator ends = cont.end();
for (; itr != ends; ++itr) out << *itr << " ";
out << endl;
return out;
}
template <typename T, unsigned int N, typename CTy, typename CTr>
typename enable_if<!is_same<T, char>::value, basic_ostream<CTy, CTr> &>::type
operator<<(basic_ostream<CTy, CTr> &out, const T (&arr)[N]) {
for (auto i = 0; i < N; ++i) out << arr[i] << " ";
out << endl;
return out;
}
template <typename T>
T gcd(T a, T b) {
T min_v = min(a, b);
T max_v = max(a, b);
while (min_v) {
T temp = max_v % min_v;
max_v = min_v;
min_v = temp;
}
return max_v;
}
template <typename T>
T lcm(T a, T b) {
return (a * b) / gcd(a, b);
}
template <typename T>
T fast_exp_pow(T base, T exp, T mod) {
long long res = 1;
while (exp) {
if (exp & 1) {
res *= base;
res %= mod;
}
exp >>= 1;
base *= base;
base %= mod;
}
return res % mod;
}
char beg_ch, end_ch;
int dur, beg_pos, end_pos;
bool cw = false, ccw = false;
void determine(char ch, int &pos) {
if (ch == 'v')
pos = 0;
else if (ch == '<')
pos = 1;
else if (ch == '^')
pos = 2;
else if (ch == '>')
pos = 3;
}
int main() {
scanf("%c %c %d", &beg_ch, &end_ch, &dur);
dur %= 4;
determine(beg_ch, beg_pos);
determine(end_ch, end_pos);
if ((beg_pos + dur) % 4 == end_pos) cw = true;
if ((beg_pos - dur + 4) % 4 == end_pos) ccw = true;
if (cw && ccw)
printf("undefined\n");
else if (cw)
printf("cw\n");
else if (ccw)
printf("ccw\n");
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
template <typename T>
T mod(T a, T b) {
T ans;
if (b == 0)
return -1;
else
ans = (a < 0 ? mod(((a % b) + b), b) : a % b);
return ans;
}
long long fast_exp(long long base, long long n, long long M) {
long long ans = 1;
while (n) {
if (n % 2 == 1) ans = (ans * base) % M;
base = (base * base) % M;
n = n >> 1;
}
return ans % M;
}
template <typename Out>
void split(const string &s, char delim, Out result) {
stringstream ss;
ss.str(s);
string item;
while (getline(ss, item, delim)) {
*(result++) = item;
}
}
vector<string> split(const string &s, char delim) {
vector<string> elems;
split(s, delim, back_inserter(elems));
return elems;
}
char cw[4] = {'^', '>', 'v', '<'};
char ccw[4] = {'^', '<', 'v', '>'};
void solve() {
char start, end;
long long n;
cin >> start >> end >> n;
n = n % 4;
char rescw = cw[((find(cw, cw + 4, start) - cw) + n) % 4];
char resccw = ccw[((find(ccw, ccw + 4, start) - ccw) + n) % 4];
if (rescw == resccw)
cout << "undefined" << endl;
else if (end == rescw)
cout << "cw" << endl;
else if (end == resccw)
cout << "ccw" << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
int t = 1;
while (t--) {
solve();
}
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.io.*;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
public class Main {
static long mod = 1000000007L;
static FastScanner scanner;
public static void main(String[] args) {
scanner = new FastScanner();
int s = toPos(scanner.nextToken());
int e = toPos(scanner.nextToken());
int n = scanner.nextInt() % 4;
if (n == 0 || n == 2) {
System.out.println("undefined");
return;
}
int ee = (s + n) % 4;
System.out.println(ee == e ? "cw" : "ccw");
}
static int toPos(String x) {
switch (x) {
case "^": return 0;
case ">": return 1;
case "v": return 2;
case "<": return 3;
}
throw new IllegalArgumentException("");
}
static class Pos implements Comparable<Pos> {
int val, ind;
public Pos(int val, int ind) {
this.val = val;
this.ind = ind;
}
@Override
public int compareTo(Pos o) {
return Integer.compare(val, o.val);
}
}
static class Pt{
long x, y;
public Pt(long x, long y) {
this.x = x;
this.y = y;
}
}
public static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String nextToken() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return st.nextToken();
}
String nextLine() {
try {
return br.readLine();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException();
}
}
int nextInt() {
return Integer.parseInt(nextToken());
}
long nextLong() {
return Long.parseLong(nextToken());
}
double nextDouble() {
return Double.parseDouble(nextToken());
}
int[] nextIntArray(int n) {
int[] res = new int[n];
for (int i = 0; i < n; i++) res[i] = nextInt();
return res;
}
long[] nextLongArray(int n) {
long[] res = new long[n];
for (int i = 0; i < n; i++) res[i] = nextLong();
return res;
}
String[] nextStringArray(int n) {
String[] res = new String[n];
for (int i = 0; i < n; i++) res[i] = nextToken();
return res;
}
}
static class PrefixSums {
long[] sums;
public PrefixSums(long[] sums) {
this.sums = sums;
}
public long sum(int fromInclusive, int toExclusive) {
if (fromInclusive > toExclusive) throw new IllegalArgumentException("Wrong value");
return sums[toExclusive] - sums[fromInclusive];
}
public static PrefixSums of(int[] ar) {
long[] sums = new long[ar.length + 1];
for (int i = 1; i <= ar.length; i++) {
sums[i] = sums[i - 1] + ar[i - 1];
}
return new PrefixSums(sums);
}
public static PrefixSums of(long[] ar) {
long[] sums = new long[ar.length + 1];
for (int i = 1; i <= ar.length; i++) {
sums[i] = sums[i - 1] + ar[i - 1];
}
return new PrefixSums(sums);
}
}
static class ADUtils {
static void sort(int[] ar) {
Random rnd = ThreadLocalRandom.current();
for (int i = ar.length - 1; i > 0; i--)
{
int index = rnd.nextInt(i + 1);
// Simple swap
int a = ar[index];
ar[index] = ar[i];
ar[i] = a;
}
Arrays.sort(ar);
}
static void sort(long[] ar) {
Random rnd = ThreadLocalRandom.current();
for (int i = ar.length - 1; i > 0; i--)
{
int index = rnd.nextInt(i + 1);
// Simple swap
long a = ar[index];
ar[index] = ar[i];
ar[i] = a;
}
Arrays.sort(ar);
}
}
static class MathUtils {
static long[] FIRST_PRIMES = {
2, 3, 5, 7, 11, 13, 17, 19, 23, 29,
31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
73, 79, 83, 89 , 97 , 101, 103, 107, 109, 113,
127, 131, 137, 139, 149, 151, 157, 163, 167, 173,
179, 181, 191, 193, 197, 199, 211, 223, 227, 229,
233, 239, 241, 251, 257, 263, 269, 271, 277, 281,
283, 293, 307, 311, 313, 317, 331, 337, 347, 349,
353, 359, 367, 373, 379, 383, 389, 397, 401, 409,
419, 421, 431, 433, 439, 443, 449, 457, 461, 463,
467, 479, 487, 491, 499, 503, 509, 521, 523, 541,
547, 557, 563, 569, 571, 577, 587, 593, 599, 601,
607, 613, 617, 619, 631, 641, 643, 647, 653, 659,
661, 673, 677, 683, 691, 701, 709, 719, 727, 733,
739, 743, 751, 757, 761, 769, 773, 787, 797, 809,
811, 821, 823, 827, 829, 839, 853, 857, 859, 863,
877, 881, 883, 887, 907, 911, 919, 929, 937, 941,
947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013,
1019, 1021, 1031, 1033, 1039, 1049, 1051};
static long[] primes(long to) {
long[] result = Arrays.copyOf(FIRST_PRIMES, 10000);
int size = FIRST_PRIMES.length;
a:
for (long t = 1061; t <= to; t++) {
for (int i = 0; i < size; i++) {
if (t % result[i] == 0) {
continue a;
}
}
result[size++] = t;
}
return Arrays.copyOf(result, size);
}
static long modpow(long b, long e, long m) {
long result = 1;
while (e > 0) {
if ((e & 1) == 1) {
/* multiply in this bit's contribution while using modulus to keep
* result small */
result = (result * b) % m;
}
b = (b * b) % m;
e >>= 1;
}
return result;
}
static long submod(long x, long y, long m) {
return (x - y + m) % m;
}
}
} | JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | pos=input().split()
p1=0;
p2=0
if(pos[0]=='^'): p1=0
if(pos[0]=='>'): p1=1
if(pos[0]=='v'): p1=2
if(pos[0]=='<'): p1=3
if(pos[1]=='^'): p2=0
if(pos[1]=='>'): p2=1
if(pos[1]=='v'): p2=2
if(pos[1]=='<'): p2=3
s=int(input())
s=s%4;
if((p1+s)%4==(p1-s)%4):
print('undefined')
elif((p1+s)%4==p2):
print('cw')
else:
print('ccw') | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
char a, b;
cin >> a >> b;
int n;
cin >> n;
n = n % 4;
if (n == 0) {
cout << "undefined";
return 0;
}
int arr[] = {118, 60, 94, 62};
int arr2[] = {118, 62, 94, 60};
int i = 0;
for (i = 0; i < 4; i++) {
if (a == arr[i]) break;
}
char c = arr[i];
for (int j = 1; j <= n; j++) {
i = (i + 1) % 4;
c = arr[i];
}
int k = 0;
for (k = 0; k < 4; k++) {
if (a == arr2[k]) break;
}
char d = arr[k];
for (int j = 1; j <= n; j++) {
k = (k + 1) % 4;
d = arr2[k];
}
if (c == b && d == b)
cout << "undefined";
else if (c == b)
cout << "cw";
else
cout << "ccw";
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
char st, ed;
char order[4] = {'v', '<', '^', '>'};
int n;
int main() {
cin >> st >> ed >> n;
n = n % 4;
int i, j, k;
for (i = 0; i < 4; i++) {
if (st == order[i]) break;
}
for (j = 0; j < 4; j++) {
if (ed == order[j]) break;
}
bool cw = false, ccw = false;
if ((j - i + 4) % 4 == n) {
cw = true;
}
if ((i - j + 4) % 4 == n) {
ccw = true;
}
if (cw && !ccw) {
printf("cw\n");
return 0;
}
if (!cw && ccw) {
printf("ccw\n");
return 0;
}
printf("undefined\n");
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | # R = lambda: map(int, raw_input().split())
start, end = raw_input().split()
seconds = int(raw_input()) % 4
cw = '^>v<' * 2
ccw = '^<v>' * 2
def ok(positions, start, end, seconds):
return positions[positions.index(start) + seconds] == end
is_cw = ok(cw, start, end, seconds)
is_cww = ok(ccw, start, end, seconds)
if is_cw and is_cww:
ans = 'undefined'
elif is_cw:
ans = 'cw'
elif is_cww:
ans = 'ccw'
else:
print 'ZALUPEHA'
exit(0)
print ans
| PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | def read(is_int,split_by):
if(is_int):
return [int(x) for x in input().split(split_by)]
else:
return [x for x in input().split(split_by)]
s,f = read(False," ")
n = int(input())
seq = ['<','^','>','v']
k = n%4
spin = "undefined"
ind_s = seq.index(s)
ind_f = seq.index(f)
# Case of k == 0 undefined
if not (s == f):
if not(k%2==0):
remind = (ind_s+k) % 4
if f == seq[remind]:
spin = "cw"
remind = (ind_s-k) % 4
if f == seq[remind]:
spin = "ccw"
print(spin)
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.util.Scanner;
/**
* Created by ARKA on 03-08-2017.
*/
public class Imperium998 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String art = sc.nextLine();
int spin = Integer.parseInt(sc.nextLine());
spin = spin%4;
String ans = "";
if(spin%2==0)
ans = "undefined";
else {
char firstCharacter = art.charAt(0);
char secondCharacter = art.charAt(2);
char[] a = {'v', '<', '^', '>'};
int placefirst = 0;
int placesecond = 0;
for (int i = 0; i < a.length; i++) {
if (a[i] == firstCharacter)
placefirst = i;
if (a[i] == secondCharacter)
placesecond = i;
}
int delta = (placesecond - placefirst + 4) % 4;
if(delta == spin){
ans = "cw";
}
else
ans = "ccw";
}
System.out.println(ans);
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
void setIO(string name = "") {
ios_base::sync_with_stdio(0);
cin.tie(0);
if ((int)(name).size()) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cout << fixed << setprecision(15);
char arr[] = {'^', '>', 'v', '<'};
char brr[] = {'^', '<', 'v', '>'};
char st, ed;
cin >> st >> ed;
long long n;
cin >> n;
long long st_ind1;
long long ed_ind1;
long long st_ind2;
long long ed_ind2;
for (long long i = 0; i < 4; i++) {
if (st == arr[i]) {
st_ind1 = i;
}
if (ed == arr[i]) {
ed_ind1 = i;
}
if (st == brr[i]) {
st_ind2 = i;
}
if (ed == brr[i]) {
ed_ind2 = i;
}
}
if (arr[(st_ind1 + n) % 4] == ed) {
if (brr[(st_ind2 + n) % 4] == ed) {
cout << "undefined" << '\n';
} else {
cout << "cw" << '\n';
}
} else if (brr[(st_ind2 + n) % 4] == ed) {
if (arr[(st_ind1 + n) % 4] == ed) {
cout << "undefined" << '\n';
} else {
cout << "ccw" << '\n';
}
} else {
cout << "undefined" << '\n';
}
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class CF426A {
public static void main(String[] args) {
char map[] = new char[256];
map['v'] = 0;
map['<'] = 1;
map['^'] = 2;
map['>'] = 3;
MyScanner in = new MyScanner();
char start = in.next().charAt(0);
char end = in.next().charAt(0);
int n = in.nextInt();
if (Math.abs(map[start] - map[end]) == 2 || Math.abs(map[start] - map[end]) == 0) {
System.out.println("undefined");
} else {
if ((map[start] + n) % 4 == map[end]) {
System.out.println("cw");
} else {
System.out.println("ccw");
}
}
}
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import sys
a = list(input().split(' '))
t = int(input())
x = t%4
if(x == 1):
if(ord(a[0]) == 94 and ord(a[1]) == 62):
print('cw')
sys.exit(0)
elif(ord(a[0]) == 62 and ord(a[1]) == 118):
print('cw')
sys.exit(0)
elif(ord(a[0]) == 118 and ord(a[1]) == 60):
print('cw')
sys.exit(0)
elif(ord(a[0]) == 60 and ord(a[1]) == 94):
print('cw')
else:
print('ccw')
elif(x == 3):
if(ord(a[0]) == 94 and ord(a[1]) == 60):
print('cw')
sys.exit(0)
elif(ord(a[0]) == 62 and ord(a[1]) == 94):
print('cw')
sys.exit(0)
elif(ord(a[0]) == 118 and ord(a[1]) == 62):
print('cw')
sys.exit(0)
elif(ord(a[0]) == 60 and ord(a[1]) == 118):
print('cw')
sys.exit(0)
else:
print('ccw')
sys.exit(0)
else:
print('undefined') | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
int trans[256];
int main() {
int from, to;
int n;
int cwpos, ccwpos;
trans[118] = 0;
trans[60] = 1;
trans[94] = 2;
trans[62] = 3;
from = trans[getchar()];
(void)getchar();
to = trans[getchar()];
(void)scanf("%d", &n);
cwpos = (from + n % 4) % 4;
ccwpos = (from + (n + 2 * (n % 2)) % 4) % 4;
if (cwpos == ccwpos)
printf("undefined\n");
else if (cwpos == to)
printf("cw\n");
else if (ccwpos == to)
printf("ccw\n");
else
printf("undefined\n");
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 |
from collections import deque
from itertools import izip
def main():
cw_chars = deque('^>v<')
ccw_chars = deque('^>v<')
start, stop = raw_input().split(' ')
turns = int(raw_input())
while cw_chars[0] != start:
cw_chars.rotate(-1)
while ccw_chars[0] != start:
ccw_chars.rotate(1)
cw_char = start
ccw_char = start
cw_chars.rotate(-1*(turns % 4))
ccw_chars.rotate(1*(turns % 4))
if cw_chars[0] == ccw_chars[0]:
print 'undefined'
elif cw_chars[0] == stop:
print 'cw'
elif ccw_chars[0] == stop:
print 'ccw'
else:
print 'undefined'
if __name__ == "__main__":
main()
| PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
static class TaskA {
private static char rot(char c, int d) {
if (d == 1) {
if (c == '<') return '^';
else if (c == '^') return '>';
else if (c == '>') return 'v';
else return '<';
} else {
if (c == '<') return 'v';
else if (c == '^') return '<';
else if (c == '>') return '^';
else return '>';
}
}
public void solve(int testNumber, InputReader in, PrintWriter out) {
char s = in.nextChar();
char d = in.nextChar();
int n = in.nextInt();
char c1 = s, c2 = s;
n = n % 4;
while (n-- > 0) {
c1 = rot(c1, 1);
c2 = rot(c2, 2);
}
if (c1 == d && c2 == d) out.print("undefined");
else if (c1 == d) out.print("cw");
else if (c2 == d) out.print("ccw");
else out.print("undefined");
}
}
static class InputReader {
private int lenbuf = 0;
private int ptrbuf = 0;
private InputStream in;
private byte[] inbuf = new byte[1024];
public InputReader(InputStream in) {
this.in = in;
}
private int readByte() {
if (lenbuf == -1) throw new InputMismatchException();
if (ptrbuf >= lenbuf) {
ptrbuf = 0;
try {
lenbuf = in.read(inbuf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0) return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
private int skip() {
int b;
while ((b = readByte()) != -1 && isSpaceChar(b)) ;
return b;
}
public int nextInt() {
int num = 0, b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
public char nextChar() {
return (char) skip();
}
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | r = 'v<^>'
a, b = map(r.find, input().split())
n, a = int(input()), (b - a + 4) % 4
print('undefined' if a == 2 or a == 0 else 'cw' if n % 4 == a else 'ccw')
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | first, last = input().split()
n = int(input())
cw = ['^', '>', 'v', '<', '^', '>', 'v', '<']
ccw = ['^', '<', 'v', '>', '^', '<', 'v', '>']
tmp1 = ''
tmp2 = ''
flag_cw = False
flag_ccw = False
movement = n % 4
tmp1 = cw[cw.index(first) + movement]
if tmp1 == last:
flag_cw = True
tmp2 = ccw[ccw.index(first) + movement]
if tmp2 == last:
flag_ccw = True
if flag_cw == flag_ccw == True:
print('undefined')
elif flag_cw == True:
print('cw')
else:
print('ccw') | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | M, A = map(str, input().split())
N = int(input())
Dee =['v', '<', '^', '>']
P = Dee.index(M)
Q = Dee.index(A)
if N%4 ==2 or N%4 == 0:
print('undefined')
exit()
elif (Q-P)%4 == N%4:
print('cw')
exit()
else:
print('ccw')
exit() | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | initial,final = input().split()
cw_res, ccw_res = initial,initial
n = int(input())
n = n%4
ccw = {
'<': 'v',
'>': '^',
'v': '>',
'^': '<'
}
cc = {
'<': '^',
'>': 'v',
'^': '>',
'v': '<'
}
for i in range(n):
cw_res = cc[ cw_res ]
ccw_res = ccw[ ccw_res ]
if cw_res == ccw_res:
print('undefined')
elif cw_res == final:
print('cw')
else:
print('ccw')
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
long long readll() {
bool minus = false;
long long result = 0;
char ch;
ch = getchar();
while (true) {
if (ch == '-') break;
if (ch >= '0' && ch <= '9') break;
ch = getchar();
}
if (ch == '-')
minus = true;
else
result = ch - '0';
while (true) {
ch = getchar();
if (ch < '0' || ch > '9') break;
result = result * 10 + (ch - '0');
}
if (minus)
return -result;
else
return result;
}
int readint() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
const int MOD = 1e9 + 7;
const int MX = 1e5 + 10;
char pos[] = {'v', '<', '^', '>'};
int main() {
int pos1, pos2;
char start, end;
cin >> start >> end;
for (int i = 0; i < (int)4; i++) {
if (pos[i] == start) pos1 = i;
if (pos[i] == end) pos2 = i;
}
int n;
cin >> n;
if (n % 4 == 0 || n % 4 == 2)
puts("undefined");
else {
bool f = true;
int l = n % 4;
for (int i = 0; i < (int)l; i++) {
pos1++;
if (pos1 == 4) pos1 = 0;
}
if (pos[pos1] != end) f = false;
if (f)
puts("cw");
else
puts("ccw");
}
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | d = input().replace(" ", "")
n = int(input())
n = n % 4
cw1 = ["^>", ">v", "v<", "<^"]
cw3 = ["^<", ">^", "v>", "<v"]
if d == "^v" or d == "v^" or d == "<>" or \
d == "vv" or d == "^^" or d == ">>" or \
d == "<<" or d == "><":
print("undefined")
elif d in cw1 and n == 1 or d in cw3 and n == 3:
print("cw")
else:
print("ccw") | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 |
s,e=map(str,input().split())
n=int(input())
def clk(st,n,lis):
sti=lis.index(st)
n=n%4
p=3-sti
if(n<=p):
return(lis[sti+n])
else:
n=n-p
return(lis[n-1])
def aclk(st,n,lis):
sti=lis.index(st)
n=n%4
if(n<=sti):
return(lis[sti-n])
else:
n=n-sti
return(lis[-n])
lis=['v', '<', '^' ,'>']
ck=clk(s,n,lis)
ack=aclk(s,n,lis)
if(ck==e and ack!=e):
print('cw')
elif(ack==e and ck!=e):
print('ccw')
else:
print('undefined') | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
char a[4] = {'v', '<', '^', '>'};
char x, y, z;
cin >> x >> y;
int n, w, k, i;
cin >> n;
n = n % 4;
if (n % 2 == 0)
cout << "undefined" << endl;
else {
for (i = 0; i < 4; i++) {
if (a[i] == x) w = i;
}
if (w + n > 3)
k = w + n - 4;
else
k = w + n;
if (a[k] == y)
cout << "cw" << endl;
else
cout << "ccw" << endl;
}
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | def func(d , e , n , c ):
if(c==0) :
f = ['^' , '>' , 'v' , '<']
for i in range(0 , 4):
if(d==f[i]):
d = i;
break;
pos = (d+n)%4;
if(f[pos]==e) :
return 1;
else :
return 0;
else :
f = ['^' , '<' , 'v' , '>']
for i in range(0 , 4):
if(d==f[i]):
d = i;
break;
pos = (d+n)%4;
if(f[pos]==e) :
return 1;
else :
return 0;
s = list(map( str , raw_input().split()))
n = (int)(input())
a = func(s[0] , s[1] , n , 0)
b = func(s[0] , s[1] , n , 1)
if a==1 and b==1:
print("undefined")
elif a==1:
print("cw")
else:
print("ccw") | PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | def func(d , e , n , f ):
for i in range(0 , 4):
if(d==f[i]):
d = i;
break;
pos = (d+n)%4;
if(f[pos]==e) :
return 1;
else :
return 0;
s = list(map( str , raw_input().split()))
n = (int)(input())
p = ['^' , '>' , 'v' , '<']
a = func(s[0] , s[1] , n , p)
g = ['^' , '<' , 'v' , '>']
b = func(s[0] , s[1] , n , g)
if a==1 and b==1:
print("undefined")
elif a==1:
print("cw")
else:
print("ccw") | PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
int main() {
char first, last, c;
long long int sec, s = 0, s1 = 0, ans;
scanf("%c%c%c%I64d", &first, &c, &last, &sec);
ans = sec % 4;
if (first == 'v') {
if (ans == 1) {
if (last != '<') s = 1;
} else if (ans == 2) {
if (last != '^') s = 1;
} else if (ans == 3) {
if (last != '>') s = 1;
} else if (ans == 0) {
if (last != 'v') s = 1;
}
if (ans == 1) {
if (last != '>') s1 = 1;
} else if (ans == 2) {
if (last != '^') s1 = 1;
} else if (ans == 3) {
if (last != '<') s1 = 1;
} else if (ans == 0) {
if (last != 'v') s1 = 1;
}
} else if (first == '>') {
if (ans == 1) {
if (last != 'v') s = 1;
} else if (ans == 2) {
if (last != '<') s = 1;
} else if (ans == 3) {
if (last != '^') s = 1;
} else if (ans == 0) {
if (last != '>') s = 1;
}
if (ans == 1) {
if (last != '^') s1 = 1;
} else if (ans == 2) {
if (last != '<') s1 = 1;
} else if (ans == 3) {
if (last != 'v') s1 = 1;
} else if (ans == 0) {
if (last != '>') s1 = 1;
}
} else if (first == '^') {
if (ans == 1) {
if (last != '>') s = 1;
} else if (ans == 2) {
if (last != 'v') s = 1;
} else if (ans == 3) {
if (last != '<') s = 1;
} else if (ans == 0) {
if (last != '^') s = 1;
}
if (ans == 1) {
if (last != '<') s1 = 1;
} else if (ans == 2) {
if (last != 'v') s1 = 1;
} else if (ans == 3) {
if (last != '>') s1 = 1;
} else if (ans == 0) {
if (last != '^') s1 = 1;
}
}
if (first == '<') {
if (ans == 1) {
if (last != '^') s = 1;
} else if (ans == 2) {
if (last != '>') s = 1;
} else if (ans == 3) {
if (last != 'v') s = 1;
} else if (ans == 0) {
if (last != '<') s = 1;
}
if (ans == 1) {
if (last != 'v') s1 = 1;
} else if (ans == 2) {
if (last != '>') s1 = 1;
} else if (ans == 3) {
if (last != '^') s1 = 1;
} else if (ans == 0) {
if (last != '<') s1 = 1;
}
}
if (s == 0 && s1 == 0)
printf("undefined\n");
else if (s == 0)
printf("cw\n");
else if (s1 == 0)
printf("ccw\n");
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | from random import random
import math
import re
import fractions
t = {"<":0,"^":1,">":2,"v":3}
s, d = raw_input().split(" ")
n = input() % 4
# print n, (t[d] - t[s]) % 4
if n % 2 == 0:
print "undefined"
elif (t[d] - t[s]) % 4 == n:
print "cw"
elif (t[d] - t[s]) % 4 == (4 - n)%4:
print "ccw"
else:
print "undefined"
| PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
char a, b;
scanf("%c %c", &a, &b);
int k, arr[4] = {118, 60, 94, 62}, fir, sec;
scanf("%d", &k);
k %= 4;
for (int i = 0; i < 4; i++) {
if (a == arr[i]) fir = i;
if (b == arr[i]) sec = i;
}
if ((fir + k) % 4 == sec && (sec + k) % 4 == fir)
printf("undefined");
else if ((fir + k) % 4 == sec)
printf("cw");
else if ((sec + k) % 4 == fir)
printf("ccw");
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Sanket Makani
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
static class TaskA {
public void solve(int testNumber, InputReader sc, PrintWriter w) {
char c1 = sc.next().charAt(0);
char c2 = sc.next().charAt(0);
int n = sc.nextInt();
n %= 4;
char arr[] = {'v', '<', '^', '>'};
int index = 0;
int index1 = 0;
for (int i = 0; i < 4; i++) {
if (c1 == arr[i])
index = i;
if (c2 == arr[i])
index1 = i;
}
boolean cw = (index + n) % 4 == index1;
boolean ccw = (index1 + n) % 4 == index;
if (cw && ccw)
w.println("undefined");
else if ((index + n) % 4 == index1)
w.println("cw");
else if ((index1 + n) % 4 == index)
w.println("ccw");
else
w.println("undefined");
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private InputReader.SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
}
while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | l = ['^','>','v','<']
temp = raw_input().split()
ind1 = l.index(temp[0])
ind2 = l.index(temp[1])
n = input()
if((ind1+n)%4==ind2 and (ind2+n)%4==ind1):
print "undefined"
elif ((ind1+n)%4==ind2):
print 'cw'
else:
print 'ccw'
| PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
using namespace std;
int frr(char c) {
if (c == 94) {
return 0;
} else if (c == '>') {
return 1;
} else if (c == 'v') {
return 2;
} else if (c == '<') {
return 3;
}
return -1;
}
int main() {
char f, s;
cin >> f >> s;
int n;
cin >> n;
n %= 4;
int init = frr(f);
int final = frr(s);
int mc = (init + n) % 4;
int ml = (8 + init - n) % 4;
if (mc == final && ml != final) {
cout << "cw" << endl;
} else if (ml == final && mc != final) {
cout << "ccw" << endl;
} else {
cout << "undefined" << endl;
}
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | first, last = input().split()
n = int(input())
directions = {"^":0, ">":1, "v":2, "<":3}
first = directions[first]
last = directions[last]
cw = False
ccw = False
if (last - first)%4 == n%4:
cw = True
if (first - last)%4 == n%4:
ccw = True
if ccw and not cw:
print("ccw")
elif cw and not ccw:
print("cw")
else:
print("undefined") | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | def cw(s):
if s == 'v':
return ['v','<','^','>']
elif s == '<':
return ['<','^','>', 'v']
elif s == '^':
return ['^','>', 'v', '<']
else:
return ['>', 'v', '<', '^']
def solve(n,start,end):
arr_cw = cw(start)
arr_ccw = list(reversed(arr_cw[1:]+arr_cw[0:1]))
if n >= 4 :
n = n%4
expected_cw = arr_cw[n]
expected_ccw = arr_ccw[n]
if expected_ccw == expected_cw:
return 'undefined'
if end == expected_cw:
return 'cw'
if end == expected_ccw:
return 'ccw'
def main():
res = list(input().split(' '))
n = int(input())
# for i in range(n):
# arr.append(list(map(int, list(input()))))
print(solve(n,*res))
main() | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | from sys import stdin
data = stdin.readline().rstrip().split()
n = int(stdin.readline().rstrip()) % 4
dmap = {
'^': 0,
'>': 1,
'v': 2,
'<': 3
}
a, b = dmap[data[0]], dmap[data[1]]
if (a + n) % 4 == b and (a - n) % 4 == b:
print('undefined')
elif (a + n) % 4 == b:
print('cw')
else:
print('ccw')
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | sign = input().split()
time = int(input())
types = 'v<^>'
i = [i for i, x in enumerate(types) if sign[0] == x][0]
turn1 = types[(i+time) % 4]
turn2 = types[(i-time) % 4]
if turn1 == sign[1] != turn2:
print('cw')
elif turn2 == sign[1] != turn1:
print('ccw')
else:
print('undefined')
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
char a, b;
long long int n;
cin >> a >> b >> n;
n = n % 4;
long long int first, second;
if (a == '^')
first = 0;
else if (a == '>')
first = 1;
else if (a == 'v')
first = 2;
else
first = 3;
if (b == '^')
second = 0;
else if (b == '>')
second = 1;
else if (b == 'v')
second = 2;
else
second = 3;
bool cw = false, ccw = false;
if ((first + n) % 4 == second) cw = true;
if ((first + 4 - n) % 4 == second) ccw = true;
if (cw && !ccw)
cout << "cw";
else if (ccw && !cw)
cout << "ccw";
else
cout << "undefined";
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | def NextR (c):
if c == 'v': return '<';
if c == '<': return '^';
if c == '^': return '>';
if c == '>': return 'v';
def NextL (c):
if c == 'v': return '>';
if c == '>': return '^';
if c == '^': return '<';
if c == '<': return 'v';
c1, c2 = input().split();
n = int (input());
nn = n % 4; cr = cl = c1;
for i in range (nn):
cl = NextR(cl);
for i in range (nn):
cr = NextL(cr);
if cl == cr:
print("undefined");
raise SystemExit;
if cl != c2 and cr != c2:
print("undefined");
raise SystemExit;
if cl == c2:
print("cw");
else:
print("ccw");
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int bata(char c) {
if (c == '^') return 0;
if (c == '>') return 1;
if (c == 'v') return 2;
if (c == '<') return 3;
}
int main() {
ios_base::sync_with_stdio(false);
char a, b, c, d;
long long x, y, z, i, j, n, k, w;
cin >> a >> b;
cin >> n;
n %= 4;
x = bata(a);
y = bata(b);
z = (x + n) % 4;
w = (x + 4 - n) % 4;
if (z == y && w != y) {
cout << "cw";
} else if (z != y && w == y)
cout << "ccw";
else
cout << "undefined";
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | s,f = input().strip().split()
n = int(input())
rot = ['^','>','v','<']
d = {'^':0,'>':1,'v':2,'<':3}
cw = (d[s] + n)%4
ccw = (d[s] - n)%4
if cw == ccw:
print('undefined')
elif rot[cw] == f:
print('cw')
else: print('ccw')
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | s, e = map(str, raw_input().split())
n = int(raw_input()) % 4
mapping = {
'v' : 0,
'<' : 1,
'^' : 2,
'>' : 3
}
def simulate(s, e, step):
s = mapping[s]
e = mapping[e]
c = 0
while s != e:
s = (s + step) % 4
c += 1
return c
cw = simulate(s, e, 1)
ccw = simulate(s, e, -1)
if cw == n:
if ccw == n:
print("undefined")
else:
print("cw")
else:
print("ccw")
| PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | a = 'v<^>'
d = dict()
d['v'] = 0
d['<'] = 1
d['^'] = 2
d['>'] = 3
s, e = map(lambda x: d[x], input().split())
n = int(input()) % 4
flag_left = False
flag_right = False
if a[(s + n) % 4] == a[e]:
flag_left = True
if a[(s - n) % 4] == a[e]:
flag_right = True
if flag_left and flag_right:
print('undefined')
elif flag_left:
print('cw')
elif flag_right:
print('ccw')
else:
print('undefined')
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | A,B = input().split()
C = int(input())
if A == "^":
a = 0
elif A == ">":
a = 1
elif A == "v":
a = 2
else:
a = 3
if B == "^":
b = 0
elif B == ">":
b = 1
elif B == "v":
b = 2
else:
b = 3
c = C % 4
if (a + c) % 4 == b and (a - c) % 4 == b:
print("undefined")
elif (a + c) % 4 == b:
print("cw")
elif (a - c) % 4 == b:
print("ccw")
else:
print("undefined") | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | d={"v":["v","<","^",">"],"<":["<","^",">","v"],"^":["^",">","v","<"],">":[">","v","<","^"]}
start,end=map(str,input().split())
n=int(input())
clock=d[start]
temp=clock[1:]
temp=temp[::-1]
anti=[clock[0]]+temp
# print(clock,anti)
mod=n%4
if(end==clock[mod] and end==anti[mod]):
print("undefined")
elif(end==clock[mod]):
print("cw")
else:
print("ccw") | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1073741824")
#pragma GCC optimize("Ofast")
using namespace std;
using namespace placeholders;
const int inf = (int)1e9 + 9;
const long long linf = (long long)1e18 + 1;
const long double eps = 1e-9;
const int mod = (int)1e9 + 7;
const int smod = 16769023;
const long long lmod = 27644437;
const long double pi = acos(-1);
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
srand(time(0));
char a, b;
cin >> a >> b;
int t;
cin >> t;
map<char, int> kek = {{'^', 0}, {'>', 1}, {'v', 2}, {'<', 3}};
a = kek[a];
b = kek[b];
if ((a + t) % 4 == b) {
if ((a - (t % 4) + 4) % 4 == b) {
cout << "undefined";
return 0;
}
cout << "cw";
return 0;
}
cout << "ccw";
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.util.*;
import java.io.*;
import java.math.BigInteger;
/**
*
*/
public class Main {
static int mod = (int)1e9+7;
static void solve() {
char[] c = sc.nextLine().toCharArray();
int n = sc.nextInt();
int x=0,y=0;
if(c[0]==94) x=0;
else if(c[0]==62) x=1;
else if(c[0]==118) x=2;
else x=3;
if(c[2]==94) y=0;
else if(c[2]==62) y=1;
else if(c[2]==118) y=2;
else y=3;
int dif = x-y;
if((n&1)==0) out.println("undefined");
else
{
n=n%4;
if(((x+n)%4)==y)
{
out.println("cw");
}
else out.println("ccw");
}
out.close();
}
static InputReader sc = new InputReader(System.in);
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) {
new Thread(null,new Runnable() {
@Override
public void run() {
try{
solve();
}
catch(Exception e){
e.printStackTrace();
}
}
},"1",1<<26).start();
}
static class Pair implements Comparable<Pair>{
int x,y;
Pair (int x,int y){
this.x = x;
this.y = y;
}
public int compareTo(Pair o)
{
return -Integer.compare(this.x,o.x);
}
@Override
public String toString() {
return x + " "+ y ;
}
public int hashCode() {
return new Long(x).hashCode() * 31 + new Long(y).hashCode();
}
}
static void debug(Object... o) {
System.out.println(Arrays.deepToString(o));
}
static class InputReader {
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int snext() {
if (snumChars == -1)
throw new InputMismatchException();
if (curChar >= snumChars) {
curChar = 0;
try {
snumChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (snumChars <= 0)
return -1;
}
return buf[curChar++];
}
public int nextInt() {
int c = snext();
while (isSpaceChar(c)) {
c = snext();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = snext();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = snext();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = snext();
while (isSpaceChar(c)) {
c = snext();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = snext();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = snext();
} while (!isSpaceChar(c));
return res * sgn;
}
public int[] nextIntArray(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
public long[] nextLongArray(int n) {
long a[] = new long[n];
for (int i = 0; i < n; i++) {
a[i] = nextLong();
}
return a;
}
public String readString() {
int c = snext();
while (isSpaceChar(c)) {
c = snext();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = snext();
} while (!isSpaceChar(c));
return res.toString();
}
public String nextLine() {
int c = snext();
while (isSpaceChar(c))
c = snext();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = snext();
} while (!isEndOfLine(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
} | JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | a = [[0, 'v'], [1, '<'], [2, '^'], [3, '>']]
f, s = input().split()
n = int(input())
n = n % 4
four = 4
def o(f):
if f == 'v':
f = 0
elif f == '<':
f = 1
elif f == '^':
f = 2
else:
f = 3
return f
f = o(f)
s = o(s)
if (f == 0 and s == 2) or (f == 1 and s == 3) or (s == 0 and f == 2) or (s == 1 and f == 3) or (f == s):
print("undefined")
elif (f + n) % 4 == s:
print("cw")
else:
print("ccw")
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | s, e = raw_input().split()
n = int(raw_input())
n %= 4
def compute(s, e, n):
if n == 0 or n == 2:
return 'undefined'
sequence = 'v<^>'
s = sequence.find(s)
e = sequence.find(e)
if n == 1:
if e - s == 1 or e - s == -3:
return 'cw'
return 'ccw'
if n == 3:
if e - s == 1 or e - s == -3:
return 'ccw'
return 'cw'
print compute(s, e, n)
| PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | def solve():
cc = {
chr(118): 0, # v
chr(60): 1, # <
chr(94): 2, # ^
chr(62): 3, # >
}
q = ['v', '<', '^', '>']
q2 = ['v', '>', '^', '<', ] # in reverse
a, b = map(str, raw_input().split())
n = int(raw_input())
n = n%4
ans1 = 0
c = a
i = q.index(c)
while c != b:
i += 1
i = i % 4
c = q[i]
ans1 += 1
ans2 = 0
c = a
i = q2.index(c)
while c != b:
i += 1
i = i % 4
c = q2[i]
ans2 += 1
#print ans1, ans2
if ans1 == n and ans2 != n:
print 'cw'
elif ans2 == n and ans1 != n:
print 'ccw'
else:
print 'undefined'
solve()
| PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | pos = "v<^>v<^>v<^>v"
s, e = raw_input().split()
n = int(raw_input()) % 4
x = pos.find(s, 4)
if n in (0, 2):
print "undefined"
elif pos[x+n] == e:
print "cw"
else:
print "ccw"
| PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.util.Scanner;
public class Codeforces {
public static void main(String[] args) {
TaskA Solver = new TaskA();
Solver.Solve();
}
private static class TaskA {
private void Solve() {
Scanner in = new Scanner(System.in);
String S = in.nextLine();
char s = S.charAt(0);
char f = S.charAt(2);
String direct1 = "v<^>v<^>";
String direct2 = "v>^<v>^<";
int n = in.nextInt();
n %= 4;
boolean fl1 = false, fl2 = false;
if (F(n, s, f, direct1))
fl1 = true;
if (F(n, s, f, direct2))
fl2 = true;
if (fl1 && fl2)
System.out.println("undefined");
else {
if (fl1)
System.out.println("cw");
if (fl2)
System.out.println("ccw");
}
}
private static boolean F(int n, char s, char f, String direct) {
int i = direct.indexOf(s);
return direct.charAt(i + n) == f;
}
}
} | JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
void cass() {
ios::sync_with_stdio(0);
cin.tie(0);
}
string s1, s2;
int st, fi, n;
int get(string s) {
if (s == "v") return 1;
if (s == "<") return 2;
if (s == "^") return 3;
return 0;
}
void read() {
cin >> s1 >> s2 >> n;
st = get(s1);
fi = get(s2);
if ((n % 4 + st) % 4 == fi && (n % 4 + (4 - st + 1)) % 4 == (4 - fi + 1) % 4)
cout << "undefined";
else if ((n % 4 + st) % 4 == fi)
cout << "cw";
else if ((n % 4 + (4 - st + 1)) % 4 == (4 - fi + 1) % 4)
cout << "ccw";
}
int main() {
cass();
read();
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int N = 2e6 + 13, M = N;
long long n, m, k, v, u, w, c, q, qVal;
void solve() {
char s, e;
char arr[4] = {'v', '<', '^', '>'};
cin >> s >> e;
int idx = 0, spun = 0;
cin >> spun;
for (int i = 0; i < 4; i++) {
if (s == arr[i]) {
idx = i;
}
}
int cw = (idx + spun) % 4;
int ccw = ((idx - spun) + 4) % 4;
if (abs(idx - cw) == 2 || abs(idx - ccw) == 2 || idx == cw)
cout << "undefined\n";
else if (arr[cw] == e)
cout << "cw\n";
else
cout << "ccw\n";
}
int main() {
solve();
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const string cw = "v<^>";
const string ccw = "v>^<";
map<char, int> mp1{{'v', 0}, {'<', 1}, {'^', 2}, {'>', 3}};
map<char, int> mp2{{'v', 0}, {'>', 1}, {'^', 2}, {'<', 3}};
int main() {
std::ios::sync_with_stdio(false);
bool f1 = false;
bool f2 = false;
char s, e;
cin >> s >> e;
int n;
cin >> n;
int x = mp1[s];
int y = mp1[e];
if ((x + n) % 4 == y) {
f1 = true;
}
int x1 = mp2[s];
int y1 = mp2[e];
if ((x1 + n) % 4 == y1) {
f2 = true;
}
if (f1 == f2)
cout << "undefined\n";
else if (f1 == true)
cout << "cw\n";
else
cout << "ccw\n";
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.util.*;
public class Darshjava
{
public static void main(String args [])
{
Scanner enter = new Scanner (System.in) ;
char s = enter.next().charAt(0) , e = enter.next().charAt(0) ;
int n = enter.nextInt();
if (n % 4 == 0 && s == e)System.out.println("undefined");
else if(n % 4 == 2 && s == 118 && e == 94) System.out.println("undefined");
else if (n % 4 == 2 && s == 94 && e == 118) System.out.println("undefined");
else if (n % 4 == 2 && s == 60 && e == 62) System.out.println("undefined");
else if (n % 4 == 2 && s == 62 && e == 60) System.out.println("undefined");
else if (n % 4 == 1 && s == 94 && e == 60) System.out.println("ccw");
else if (n % 4 == 1 && s == 94 && e == 62) System.out.println("cw");
else if (n % 4 == 1 && s == 118 && e == 60) System.out.println("cw");
else if (n % 4 == 1 && s == 118 && e == 62) System.out.println("ccw");
else if (n % 4 == 1 && s == 60 && e == 118) System.out.println("ccw");
else if (n % 4 == 1 && s == 60 && e == 94) System.out.println("cw");
else if (n % 4 == 1 && s == 62 && e == 118) System.out.println("cw");
else if (n % 4 == 1 && s == 62 && e == 94) System.out.println("ccw");
else if (n % 4 == 3 && s == 94 && e == 60) System.out.println("cw");
else if (n % 4 == 3 && s == 94 && e == 62) System.out.println("ccw");
else if (n % 4 == 3 && s == 118 && e == 60) System.out.println("ccw");
else if (n % 4 == 3 && s == 118 && e == 62) System.out.println("cw");
else if (n % 4 == 3 && s == 60 && e == 118) System.out.println("cw");
else if (n % 4 == 3 && s == 60 && e == 94) System.out.println("ccw");
else if (n % 4 == 3 && s == 62 && e == 118) System.out.println("cw");
else if (n % 4 == 3 && s == 62 && e == 94) System.out.println("ccw");
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
map<char, int> m;
int main() {
m['v'] = 0;
m['<'] = 1;
m['^'] = 2;
m['>'] = 3;
char a, b;
int n;
cin >> a >> b >> n;
n %= 4;
int x = m[b] - m[a];
if (x < 0) x += 4;
if (n == 0 || n == 2)
cout << "undefined";
else if (x == n)
cout << "cw";
else if (x == 4 - n)
cout << "ccw";
else
cout << "undefined";
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Codeforces {
private static final Scanner sc = new Scanner(System.in);
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
private static final long MOD = (long) (1e9 + 7);
public static int[] LPS(String p){
int[] lps = new int[p.length()];
int i=1;
int j=0;
while (i < p.length()){
if (p.charAt(i) == p.charAt(j)){
lps[i] = j+1;
i++;
j++;
}
else{
if (j == 0){
lps[i] = 0;
i++;
}
else{
j = lps[j-1];
}
}
}
return lps;
}
public static void KMP(String text,String pattern){
int[] lps = LPS(pattern);
int i = 0;
int j = 0;
ArrayList<Integer> matches = new ArrayList<>();
while (i < text.length()){
if (text.charAt(i) == pattern.charAt(j)){
i++;
j++;
}
else{
if (j != 0){
j = lps[j-1];
}
else {
i++;
}
}
if (j == pattern.length()) {
matches.add(i - j);
j = lps[j-1];
}
}
for (int x : matches){
System.out.println("Match at : " + x);
}
}
private static class SegmentTree{
private long[] st;
private int size;
private int n;
private long[] a;
SegmentTree(long[] a,int n){
this.size = 4*n;
this.n = n;
this.a = a;
st = new long[size];
//Arrays.fill(st,Integer.MIN_VALUE);
buildSegmentTree(0,0,n-1);
//printSegmentTree();
}
public long buildSegmentTree(int index,int l,int r){
if (l == r){
st[index] = a[l];
return a[l];
}
int mid = (r+l) >> 1;
return st[index] = buildSegmentTree(2*index+1,l,mid) + buildSegmentTree(2*index+2,mid+1,r);
}
public void printSegmentTree(){
for (long x : st){
System.out.print(x + " ");
}
System.out.println();
}
public long query(int ql,int qr){
return getQuery(0,0,n-1,ql-1,qr-1);
}
private long getQuery(int index,int sl,int sr,int ql,int qr){
//System.out.println("#" + index);
if (qr < sl || ql > sr)
return 0;
if (ql <= sl && qr >= sr)
return st[index];
int mid = (sr + sl) >> 1;
return getQuery(2*index+1,sl,mid,ql,qr) + getQuery(2*index+2,mid+1,sr,ql,qr);
}
public void update(int i,long newVal){
//long diff = newVal - a[i];
a[i] = newVal;
updateSegmentTree(0,i,0,n-1,newVal);
}
private void updateSegmentTree(int index,int i,int sl,int sr,long diff){
if (sl == sr){
st[index] = diff;
return;
}
int mid = (sl + sr) >> 1;
if (i <= mid)
updateSegmentTree(2*index+1,i,sl,mid,diff);
else
updateSegmentTree(2*index+2,i,mid+1,sr,diff);
st[index] = st[2*index+1] + st[2*index+2];
}
}
public static class Pair<T1,T2>{
T1 first;
T2 second;
Pair(T1 a,T2 b){
this.first = a;
this.second = b;
}
@Override
public String toString() {
return "[" + first + ", " + second + "]";
}
}
public static long GCD(long a,long b){
if (b == 0)
return a;
return GCD(b,a%b);
}
static int highestPowerOf2(int n) {
int p = (int)(Math.log(n) /
Math.log(2));
return (int)Math.pow(2, p);
}
public static int binSearch(long[] a,long x){
int l = 0;
int r = a.length - 1;
while (l <= r){
int mid = l + (r-l)/2;
if (a[mid]==x)
return 1;
else if (a[mid] < x)
l = mid+1;
else
r = mid-1;
}
return -1;
}
public static int upperBound(long[] arr,long key){
int start=0;int end=arr.length-1;
int idx=-1;
int mid;
while(start<=end){
int i=(start+end)/2;
if(arr[i]<key){
start=i+1;
}
else if(arr[i]>key){
end=i-1;
}
else{
idx=i;
start=i+1;
}
}
return idx; }
public static int lowerBound(long[] arr,long key){
int start=0;int end=arr.length-1;
int idx=-1;
int mid;
while(start<=end){
int i=(start+end)/2;
if(arr[i]<key){
start=i+1;
}
else if(arr[i]>key){
end=i-1;
}
else{
idx=i;
end=i-1;
}
}
return idx;
}
public static int searchInsert(long[] nums, long target) {
int s=0,e=nums.length-1;
int mid;
if(target<nums[0]){
return 0;
}
while(s<=e){
mid=(s+e)/2;
if(nums[mid]>target){
e=mid-1;
}
else if(nums[mid]==target){
return mid;
}
else{
s=mid+1;
}
}
return s;
}
static boolean isPrime(long n) {
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (long i = 5; i <= Math.sqrt(n) + 1; i += 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
public static long fastExpo(long a,int n,int mod){
if (n == 0)
return 1;
else{
if ((n&1) == 1){
long x = fastExpo(a,n/2,mod);
return (((a*x)%mod)*x)%mod;
}
else{
long x = fastExpo(a,n/2,mod);
return (((x%mod)*(x%mod))%mod)%mod;
}
}
}
public static long modInverse(long n,int p){
return fastExpo(n,p-2,p);
}
public static long nCr(int n,int r,long[] fact,int mod){
long val = (((fact[n] * modInverse(fact[r],mod))%mod)*modInverse(fact[n-r],mod))%mod;
return val;
}
public static void factorial(long[] fact,int n,int mod){
for (int i=1;i<=n;i++){
fact[i] = (fact[i-1] * i)%mod;
}
}
public static int log2(long val){
return (int) Math.floor(Math.log(val)/Math.log(2));
}
public static boolean isSubSequence(String s,String t){
int i = 0;
int j = 0;
while (i < s.length() && j < t.length()){
if (s.charAt(i) == t.charAt(j))
j++;
i++;
}
return j == t.length();
}
public static ArrayList<Long> getAllFactors(long x){
ArrayList<Long> ans = new ArrayList<>();
for (long i = 1; i <= Math.sqrt(x); i++) {
if (x%i == 0){
if (x/i == i){
ans.add(i);
}
else{
ans.add(i);
ans.add(x/i);
}
}
}
return ans;
}
public static boolean isPerfectSquare(long x){
double val = Math.sqrt(x);
return val*val == (double)x;
}
public static ArrayList<Integer> buildSieve(int n){
boolean[] sieve = new boolean[n+1];
Arrays.fill(sieve,true);
sieve[0] = sieve[1] = false;
for (int i = 2; i <= Math.sqrt(n+1) ; i++) {
if (sieve[i]){
for (int j = 2*i; j < n+1; j += i) {
sieve[j] = false;
}
}
}
ArrayList<Integer> primes = new ArrayList<>();
for (int i = 0; i < sieve.length; i++) {
if (sieve[i]){
primes.add(i);
}
}
return primes;
}
public static int getLowBit(int n){
int x = 0;
while ((n&1) != 1){
x++;
n >>= 1;
}
return 1 << x;
}
public static void solve() throws IOException {
char s = sc.next().charAt(0);
char e = sc.next().charAt(0);
long n = sc.nextLong();
n = n%4;
if (n == 0 || n == 2){
System.out.println("undefined");
return;
}
if (n == 1){
if (s == '^'){
if (e == '>'){
System.out.println("cw");
}
else if (e == '<'){
System.out.println("ccw");
}
else
System.out.println("undefined");
return;
}
if (s == '>'){
if (e == 'v'){
System.out.println("cw");
}
else if (e == '^'){
System.out.println("ccw");
}
else
System.out.println("undefined");
return;
}
if (s == 'v'){
if (e == '<'){
System.out.println("cw");
}
else if (e == '>'){
System.out.println("ccw");
}
else
System.out.println("undefined");
return;
}
if (s == '<'){
if (e == '^'){
System.out.println("cw");
}
else if (e == 'v'){
System.out.println("ccw");
}
else
System.out.println("undefined");
return;
}
}
if (n == 3){
if (s == '^'){
if (e == '>'){
System.out.println("ccw");
}
else if (e == '<'){
System.out.println("cw");
}
else
System.out.println("undefined");
return;
}
if (s == '>'){
if (e == 'v'){
System.out.println("ccw");
}
else if (e == '^'){
System.out.println("cw");
}
else
System.out.println("undefined");
return;
}
if (s == 'v'){
if (e == '<'){
System.out.println("ccw");
}
else if (e == '>'){
System.out.println("cw");
}
else
System.out.println("undefined");
return;
}
if (s == '<'){
if (e == '^'){
System.out.println("ccw");
}
else if (e == 'v'){
System.out.println("cw");
}
else
System.out.println("undefined");
return;
}
}
}
public static void main(String[] args) throws IOException {
int t;
// t = sc.nextInt();
t = 1;
while (t-- > 0){
solve();
}
System.gc();
}
} | JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | i,f=list(input().split())
a=['v','<','^','>']
n=int(input())
n=n%4
q=a.index(i)
c=q+n
ac=q-n
if(c>3):
c=c%4
if(ac<0):
ac=ac%4
if (c==ac):
print('undefined')
elif (a[c]==f):
print("cw")
else:
print("ccw")
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | a={'v': 0, '<': 1, '^': 2, '>': 3}
s=input().strip().split()
n=int(input())
cw=(a[s[0]]+n)%4==a[s[1]]
cc=(a[s[0]]-n)%4==a[s[1]]
if cw and not cc: print('cw')
elif cc and not cw: print('ccw')
else: print('undefined')
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | pos = {'>': 0, 'v': 1, '<': 2, '^': 3}
s, e = input().split(' ')
spins = int(input())
x = (pos[e] - pos[s] - spins) % 4
if spins % 2 == 0:
ans = 'undefined'
elif (pos[e] - pos[s]) % 4 == spins % 4:
ans = 'cw'
elif (pos[s] - pos[e]) % 4 == spins % 4:
ans = 'ccw'
print(ans) | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | from sys import stdin
x,y = stdin.readline().split()
n = int(stdin.readline())
ans = 'undefined'
a = '^>v<'
if n%2:
n = n%4
ind = a.index(x)
if a[(ind+n)%4]== y:
ans = 'cw'
else:
ans = 'ccw'
print ans | PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | def main ():
s, e = input().split()
N = int(input())
mapping = {
"^": ">",
"<": "^",
">": "v",
"v": "<"
}
if N%2 == 0:
return "undefined"
if N%4==1:
if mapping[s] == e:
return "cw"
else:
return "ccw"
else:
if mapping[s] == e:
return "ccw"
else:
return "cw"
print(main()) | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | s,e = input().split()
n = int(input())
f = ['^','>','v','<']
a,b = 0,0
for i in range(4):
if f[i] == s:
a = i + 1
if f[i] == e:
b = i + 1
if n % 4 == 2 or n % 4 == 0:
print('undefined')
else:
if n % 4 == abs(a-b):
if a > b:
print('ccw')
else:
print('cw')
else:
if a > b:
print('cw')
else:
print('ccw')
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | def rotatecw(s):
if s == '^':
return '>'
elif s == '>':
return 'v'
elif s == 'v':
return '<'
elif s == '<':
return '^'
def rotateccw(s):
if s == '^':
return '<'
elif s == '>':
return '^'
elif s == 'v':
return '>'
elif s == '<':
return 'v'
a, b = raw_input().split()
n = int(raw_input())
spins = n%4
result = a
for i in xrange(spins):
result = rotatecw(result)
r = a
for j in xrange(spins):
r = rotateccw(r)
# print result, r, b
if result == b and r == b:
print "undefined"
elif r == b:
print "ccw"
else:
print "cw"
| PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 |
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class TryC
{
static class InputReader {
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
public InputReader(InputStream st) {
this.stream = st;
}
public int read() {
if (snumChars == -1)
throw new InputMismatchException();
if (curChar >= snumChars) {
curChar = 0;
try {
snumChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (snumChars <= 0)
return -1;
}
return buf[curChar++];
}
public int ni() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nl() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int[] nia(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = ni();
}
return a;
}
public String rs() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public String nextLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
}
static long mod=1000000007;
static BigInteger bigInteger = new BigInteger("1000000007");
static int n = (int)1e6;
static boolean[] prime;
static ArrayList<Integer> as;
static void sieve() {
Arrays.fill(prime , true);
prime[0] = prime[1] = false;
for(int i = 2 ; i * i <= n ; ++i) {
if(prime[i]) {
for(int k = i * i; k< n ; k+=i) {
prime[k] = false;
}
}
}
}
static PrintWriter w = new PrintWriter(System.out);
static char [][]sol;
public static void main(String[] args)
{
InputReader sc = new InputReader(System.in);
//PrintWriter w = new PrintWriter(System.out);
/*
prime = new boolean[n + 1];
sieve();
prime[1] = false;
*/
/*
as = new ArrayList<>();
for(int i=2;i<=1000000;i++)
{
if(prime[i])
as.add(i);
}
*/
/*
long a = sc.nl();
BigInteger ans = new BigInteger("1");
for (long i = 1; i < Math.sqrt(a); i++) {
if (a % i == 0) {
if (a / i == i) {
ans = ans.multiply(BigInteger.valueOf(phi(i)));
} else {
ans = ans.multiply(BigInteger.valueOf(phi(i)));
ans = ans.multiply(BigInteger.valueOf(phi(a / i)));
}
}
}
w.println(ans.mod(bigInteger));
*/
// MergeSort ob = new MergeSort();
// ob.sort(arr, 0, arr.length-1);
// Student []st = new Student[x];
// st[i] = new Student(i,d[i]);
//Arrays.sort(st,(p,q)->p.diff-q.diff);
int []a = new int[4];
a[0] = 118;
a[1] = 60;
a[2] = 94;
a[3] = 62;
int []a1 = new int[4];
a1[0] = 118;
a1[3] = 60;
a1[2] = 94;
a1[1] = 62;
String s = sc.rs();
String s1 = sc.rs();
int x = sc.ni();
int f = 0;
int p = 0;
for(int i=0;i<4;i++)
{
if((int)s.charAt(0) == a[i])
{
if((int)s1.charAt(0) == a[(i+x)%4])
{
p = 1;
f++;
}
}
if((int)s.charAt(0) == a1[i])
{
if((int)s1.charAt(0) == a1[(i+x)%4])
{
p = 2;
f++;
}
}
}
if(f == 0||f==2)
w.println("undefined");
else
{
if(p==1)
w.println("cw");
else if(p == 2)
w.println("ccw");
}
w.close();
}
static void maxi(int []a)
{
}
static boolean check(int p)
{
int f = 0;
while(p > 0)
{
int c = p%10;
if(c > 3 || c == 0)
{
f = 1;
break;
}
p /= 10;
}
if(f==0)
return true;
else
return false;
}
static class Student
{
int first;
int sec;
Student(int first,int sec)
{
this.first = first;
this.sec = sec;
}
}
public static long modMultiply(long one, long two) {
return (one % mod * two % mod) % mod;
}
static long fx(int m)
{
long re = 0;
for(int i=1;i<=m;i++)
{
re += (long) (i / gcd(i,m));
}
return re;
}
static long gcd(long a, long b)
{
if (a == 0)
return b;
return gcd(b%a, a);
}
static long phi(long nx)
{
// Initialize result as n
double result = nx;
// Consider all prime factors of n and for
// every prime factor p, multiply result
// with (1 - 1/p)
for (int p = 0; as.get(p) * as.get(p) <= nx; ++p)
{
// Check if p is a prime factor.
if (nx % as.get(p) == 0)
{
// If yes, then update n and result
while (nx % as.get(p) == 0)
nx /= as.get(p);
result *= (1.0 - (1.0 / (double) as.get(p)));
}
}
// If n has a prime factor greater than sqrt(n)
// (There can be at-most one such prime factor)
if (nx > 1)
result *= (1.0 - (1.0 / (double) nx));
return (long)result;
//return(phi((long)result,k-1));
}
public static int primeFactors(int n,int x)
{
as = new ArrayList<>();
int sum = 0;
// Print the number of 2s that divide n
while (n%2==0)
{
if(sum == x-1)
break;
as.add(2);
//System.out.print(2 + " ");
n /= 2;
sum++;
}
// n must be odd at this point. So we can
// skip one element (Note i = i +2)
for (int i = 3; i <= Math.sqrt(n); i+= 2)
{
// While i divides n, print i and divide n
while (n%i == 0)
{
// System.out.print(i + " ");
if(sum == x-1)
break;
as.add(i);
n /= i;
sum++;
}
}
// This condition is to handle the case whien
// n is a prime number greater than 2
if (n >= 2)
{
sum++;
as.add(n);
}
return sum;
}
static int digitsum(int x)
{
int sum = 0;
while(x > 0)
{
int temp = x % 10;
sum += temp;
x /= 10;
}
return sum;
}
static int countDivisors(int n)
{
int cnt = 0;
for (int i = 1; i*i <=n; i++)
{
if (n % i == 0 && i<=1000000)
{
// If divisors are equal,
// count only one
if (n / i == i)
cnt++;
else // Otherwise count both
cnt = cnt + 2;
}
}
return cnt;
}
static boolean isprime(int n)
{
if(n == 2)
return true;
if(n == 3)
return true;
if(n % 2 == 0)
return false;
if(n % 3 == 0)
return false;
int i = 5;
int w = 2;
while(i * i <= n)
{
if(n % i == 0)
return false;
i += w;
w = 6 - w;
}
return true;
}
static long log2(long value) {
return Long.SIZE-Long.numberOfLeadingZeros(value);
}
static boolean binarysearch(int []arr,int p,int n)
{
//ArrayList<Integer> as = new ArrayList<>();
//as.addAll(0,at);
//Collections.sort(as);
boolean re = false;
int st = 0;
int end = n-1;
while(st <= end)
{
int mid = st + (end-st)/2;
if(p > arr[mid])
{
st = mid+1;
}
else if(p < arr[mid])
{
end = mid-1;
}
else if(p == arr[mid])
{
re = true;
break;
}
}
return re;
}
/* Java program for Merge Sort */
static class MergeSort
{
// Merges two subarrays of arr[].
// First subarray is arr[l..m]
// Second subarray is arr[m+1..r]
void merge(int arr[], int l, int m, int r)
{
// Find sizes of two subarrays to be merged
int n1 = m - l + 1;
int n2 = r - m;
/* Create temp arrays */
int L[] = new int [n1];
int R[] = new int [n2];
/*Copy data to temp arrays*/
for (int i=0; i<n1; ++i)
L[i] = arr[l + i];
for (int j=0; j<n2; ++j)
R[j] = arr[m + 1+ j];
/* Merge the temp arrays */
// Initial indexes of first and second subarrays
int i = 0, j = 0;
// Initial index of merged subarry array
int k = l;
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
}
/* Copy remaining elements of L[] if any */
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
/* Copy remaining elements of R[] if any */
while (j < n2)
{
arr[k] = R[j];
j++;
k++;
}
}
// Main function that sorts arr[l..r] using
// merge()
void sort(int arr[], int l, int r)
{
if (l < r)
{
// Find the middle point
int m = (l+r)/2;
// Sort first and second halves
sort(arr, l, m);
sort(arr , m+1, r);
// Merge the sorted halves
merge(arr, l, m, r);
}
}
/* A utility function to print array of size n */
}
public static int ip(String s){
return Integer.parseInt(s);
}
public static String ips(int s){
return Integer.toString(s);
}
} | JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
int dr[4] = {-1, 0, 0, 1};
int dc[4] = {0, 1, -1, 0};
int dx[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dy[8] = {1, 0, -1, -1, -1, 0, 1, 1};
char arr[20][20];
using namespace std;
bool inside(int x, int y) { return x >= 0 && y >= 0 && y < 10 && x < 10; }
long long int ncr(long long int n) {
if (n % 2 == 0)
return (n / 2) * (n - 1);
else
return n * ((n - 1) / 2);
}
int main() {
char a, b, c;
int n, fpos, lpos;
scanf("%c", &a);
scanf("%c", &c);
scanf("%c", &b);
scanf("%d", &n);
int d = n % 4;
if (a == 'v') {
if (b == '<') {
if (d == 1) {
printf("cw\n");
} else if (d == 3) {
printf("ccw\n");
} else
printf("undefined\n");
} else if (b == '>') {
if (d == 3) {
printf("cw\n");
} else if (d == 1) {
printf("ccw\n");
} else
printf("undefined\n");
} else
printf("undefined\n");
} else if (a == '<') {
if (b == '^') {
if (d == 1) {
printf("cw\n");
} else if (d == 3) {
printf("ccw\n");
} else
printf("undefined\n");
} else if (b == 'v') {
if (d == 3) {
printf("cw\n");
} else if (d == 1) {
printf("ccw\n");
} else
printf("undefined\n");
} else
printf("undefined\n");
} else if (a == '^') {
if (b == '>') {
if (d == 1) {
printf("cw\n");
} else if (d == 3) {
printf("ccw\n");
} else
printf("undefined\n");
} else if (b == '<') {
if (d == 3) {
printf("cw\n");
} else if (d == 1) {
printf("ccw\n");
} else
printf("undefined\n");
} else
printf("undefined\n");
} else if (a == '>') {
if (b == 'v') {
if (d == 1) {
printf("cw\n");
} else if (d == 3) {
printf("ccw\n");
} else
printf("undefined\n");
} else if (b == '^') {
if (d == 3) {
printf("cw\n");
} else if (d == 1) {
printf("ccw\n");
} else
printf("undefined\n");
} else
printf("undefined\n");
}
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | //package graphs;
import java.util.*;
public class codeforces {
//public static HashMap<Integer,List<Integer>> map;
public static int flag=0;
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s=new Scanner(System.in);
String st=s.next();
String en=s.next();
int st_index=-1;
int n=s.nextInt();
n=n%4;
char pos[]={'v','<','^','>'};
for(int i=0;i<pos.length;i++)
{
if(pos[i]==st.charAt(0))
st_index=i;
}
n=n%4;
boolean cw=pos[(st_index+n)%4]==en.charAt(0);
boolean ccw=pos[(st_index-n+4)%4]==en.charAt(0);
if(cw==true&&ccw==true)
System.out.println("undefined");
else if(cw)
System.out.println("cw");
else
System.out.println("ccw");
}
public static void ps(int ns[],int a[])
{
Stack<Integer> s=new Stack<>();
ns[0]=-1;
s.push(0);
for(int i=1;i<a.length-1;i++)
{
int eql=0;
if(a[i]==a[i-1])
eql=1;
if(eql==1)
{
while(s.size()>0&&a[i]<=a[s.peek()])
{
s.pop();
}
if(s.size()==0)
ns[i]=-1;
else
ns[i]=s.peek();
s.push(i);
}
else
{
while(s.size()>0&&a[i]<a[s.peek()])
{
s.pop();
}
if(s.size()==0)
ns[i]=-1;
else
ns[i]=s.peek();
s.push(i);
}
}
}
public static void ns(int ns[],int a[])
{
Stack<Integer> s=new Stack<>();
ns[a.length-1]=-1;
s.push(a.length-1);
for(int i=a.length-2;i>=0;i--)
{
int eql=0;
if(a[i]==a[i+1])
eql=1;
if(eql==1)
{
while(s.size()>0&&a[i]<=a[s.peek()])
{
s.pop();
}
if(s.size()==0)
ns[i]=-1;
else
ns[i]=s.peek();
s.push(i);
}
else
{
while(s.size()>0&&a[i]<a[s.peek()])
{
s.pop();
}
if(s.size()==0)
ns[i]=-1;
else
ns[i]=s.peek();
s.push(i);
}
}
}
// public static void update(per st[],long a[],int l,int r,int ind,long val,int i)
// {
//
// if(l==r)
// {a[i]=val;st[ind].f=val; return ;}
//
// int mid=(l+r)/2;
// if(i<=mid)
// update(st,a,l,mid,2*ind+1,val,i); //1 l
// else
// update(st,a,mid+1,r,2*ind+2,val,i);
//
// //st[ind]=(st[2*ind+1]+st[2*ind+2]);
// if(st[2*ind+1].f<st[2*ind+2].f)
// {
// st[ind]=new per(st[2*ind+1].f,st[2*ind+1].s);
//
// }
// else
// {
// st[ind]=new per(st[2*ind+2].f,st[2*ind+2].s);
// }
//
// }
//
// public static per build(per sg[],long a[],int l,int r,int ind)
// {
// if(l==r){
// //return sg[ind]=a[l];
// per temp=new per(a[l],l);
// sg[ind]=temp;
// return temp;
// }
//
// int mid=(l+r)>>1;
// //sg[ind].f=Math.min(build(sg, a,l,mid,2*ind+1),build(sg,a,mid+1,r,2*ind+2));
// per one=build(sg, a,l,mid,2*ind+1);
// per two=build(sg,a,mid+1,r,2*ind+2);
// if(one.f<two.f)
// {
// sg[ind]=new per(one.f,one.s);
// }
// else
// sg[ind]=new per(two.f,two.s);
//
// return sg[ind];
// }
//
// public static per query(per sg[],long a[],int l,int r,int ql,int qr,int ind)
// {
// // ql------qr (find both) // ql 1 2 3 4 5 6 qr (out) // ql --------qr (inside)
// // s-------------e // s--e s--e
// if(l>qr||r<ql)
// return new per(Long.MAX_VALUE,-1);
//
// if(ql<=l&&qr>=r)
// return sg[ind];
//
// int mid=(l+r)>>1;
// int c1=2*ind+1;
// int c2=2*ind+2;
// per one=query(sg,a,l,mid,ql,qr,c1);
// per two=query(sg,a,mid+1,r,ql,qr,c2);
// //return Math.max(query(sg,a,l,mid,ql,qr,c1),query(sg,a,mid+1,r,ql,qr,c2));
// if(one.f<two.f)
// return one;
// return two;
// }
//
public static int opp(String str,int d)
{
int count=0;
for(int i=0;i<str.length();i++)
{
if(str.charAt(i)=='1')
count++;
}
if(count<d)
return 1;
else
return 0;
}
public static int solve(int a[],int b[],int n,int m)
{
if(n==0||m==0)
return 0;
System.out.println("hi");
int op1=a[n-1]+solve(a,b,n-1,m);
int op2=b[m-1]+solve(a,b,n,m-1);
int op3=a[n-1]+b[m-1]+solve(a,b,n-1,m-1);
return Math.max(op1,Math.max(op2,op3));
}
public static int lcs(String a,String b)
{
int dp[][]=new int[a.length()+1][b.length()+1];
for(int i=1;i<dp.length;i++)
{
for(int j=1;j<dp[i].length;j++)
{
if(a.charAt(i-1)==b.charAt(j-1))
{
dp[i][j]=1+dp[i-1][j-1];
}
else
dp[i][j]=Math.max(dp[i-1][j],dp[i][j-1]);
}
}
return dp[dp.length-1][dp[0].length-1];
}
public static long solve(long base,long pow,long mod)
{
if(pow==0)
return 1L;
long temp=solve(base,pow/2,mod);
temp=((temp%5)*(temp%5))%5;
if(pow%2==1)
temp=((base%5)*(temp%5))%5;
return temp;
}
public static long gcd(long a,long b)
{
if(b==0)
return a+b;
return gcd(b,a%b);
}
public static int solve(int n,int buff,int score)
{
if(n<=0)
{
return score;
}
int op1=solve(n-1,buff,score+1);
int op2=Integer.MIN_VALUE;
int op3=Integer.MIN_VALUE;
if(buff!=0)
{
op2=solve(n-1,buff,score+buff);
}
if(n>=3)
{
op3=solve(n-3,score,2*score);
}
return Math.max(op1,Math.max(op2, op3));
}
}
class per{
int f;
int s;
per(int f,int s)
{
this.f=f;
this.s=s;
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 |
# Creating dictionary mapping out possible rotations given
# intial position of spinner.
rotations = {
'ccw':{
'<':'<v>^', 'v':'v>^<', '>':'>^<v', '^':'^<v>'
},
'cw':{
'<':'<^>v', '^':'^>v<', '>':'>v<^', 'v':'v<^>'
}
}
# Collecting problem data from codeforces.
start, end = list(input().split(' '));
seconds = int(input())
# Ascertaining if given data points to rotation being
# clockwise, counter-clockwise or undefined.
isCCW = rotations['ccw'][start][ seconds % 4 ] == end
isCW = rotations['cw'][start][ seconds % 4 ] == end
if isCCW and not isCW:
print('ccw')
elif isCW and not isCCW:
print('cw')
else:
print('undefined')
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.util.*;
import java.io.*;
public class tcsF {
static class OutputWriter
{ private PrintWriter writer;
public OutputWriter(OutputStream stream)
{writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream)));}
public OutputWriter(Writer writer)
{
this.writer = new PrintWriter(writer);
}
public void println(int x)
{
writer.println(x);
}
public void print(int x)
{
writer.print(x);
}
public void println(char x)
{
writer.println(x);
}
public void print(char x)
{
writer.print(x);
}
public void println(int array[], int size) { for (int i = 0; i < size; i++) println(array[i]);}
public void print(int array[], int size) { for (int i = 0; i < size; i++) print(array[i] + " ");}
public void println(long x)
{
writer.println(x);
}
public void print(long x)
{
writer.print(x);
}
public void println(long array[], int size) { for (int i = 0; i < size; i++) println(array[i]);}
public void print(long array[], int size) { for (int i = 0; i < size; i++) print(array[i]);}
public void println(float num)
{
writer.println(num);
}
public void print(float num)
{
writer.print(num);
}
public void println(double num)
{
writer.println(num);
}
public void print(double num)
{ writer.print(num);} public void println(String s) {writer.println(s);}
public void print(String s)
{
writer.print(s);
}
public void println()
{
writer.println();
}
public void printSpace()
{
writer.print(" ");
}
public void printf(String format, Object args)
{
writer.printf(format, args);
}
public void flush()
{
writer.flush();
}
public void close()
{
writer.close();
}
}
static class Parser {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Parser(InputStream in) {
din = new DataInputStream(in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public long nextLong() throws Exception {
long ret = 0;
byte c = read();
while (c <= ' ') c = read();
boolean neg = c == '-';
if (neg) c = read();
do {
ret = ret * 10 + c - '0';
c = read();
} while (c > ' ');
if (neg) return -ret;
return ret;
}
//reads in the next string
public String next() throws Exception {
StringBuilder ret = new StringBuilder();
byte c = read();
while (c <= ' ') c = read();
do {
ret = ret.append((char) c);
c = read();
} while (c > ' ');
return ret.toString();
}
public int nextInt() throws Exception {
int ret = 0;
byte c = read();
while (c <= ' ') c = read();
boolean neg = c == '-';
if (neg) c = read();
do {
ret = ret * 10 + c - '0';
c = read();
} while (c > ' ');
if (neg) return -ret;
return ret;
}
private void fillBuffer() throws Exception {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1) buffer[0] = -1;
}
private byte read() throws Exception {
if (bufferPointer == bytesRead) fillBuffer();
return buffer[bufferPointer++];
}
}
static class Fenwick_tree {
long BIT[];
int n;
Fenwick_tree(int n){
this.n=n;
BIT=new long[n+1];
}
void update(int x, long delta) {
for (; x <= n; x += x & -x)
BIT[x] += delta;
}
long query(int x) {
long sum = 0;
for (; x > 0; x -= x & -x)
sum += BIT[x];
return sum;
}
}
public static void main(String[] args)throws Exception {
// System.out.println(gcd(32767,2097151));
Parser s = new Parser(System.in);
OutputWriter out = new OutputWriter(System.out);
char st=s.next().charAt(0);
char end=s.next().charAt(0);
int xs=0;
int xe=0;
int ascii1=(int)st;
int ascii2=(int)end;
if(ascii1==60)
xs=1;
if(ascii1==94)
xs=2;
if(ascii1==62)
xs=3;
if(ascii2==60)
xe=1;
if(ascii2==94)
xe=2;
if(ascii2==62)
xe=3;
boolean ans1=false;
boolean ans2=false;
// boolean ans2=false;
int n=s.nextInt();
n%=4;
// System.out.println(ascii1+" "+ascii2);
if((xs+n)%4==xe)
ans1=true;
xs=3;
xe=3;
ascii1=(int)st;
ascii2=(int)end;
if(ascii1==60)
xs=2;
if(ascii1==94)
xs=1;
if(ascii1==62)
xs=0;
if(ascii2==60)
xe=2;
if(ascii2==94)
xe=1;
if(ascii2==62)
xe=0;
if((xs+n)%4==xe)
ans2=true;
if(ans1==true&&ans2==false)
System.out.println("cw");
else{
if(ans1==false&&ans2==true)
System.out.println("ccw");
else
System.out.println("undefined");
}
}}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.util.Scanner;
public class apa{
public static void main(String args[]){
long x,y,z,n;
x=0;
y=0;
Scanner sc=new Scanner(System.in);
char c1=sc.next().charAt(0);
char c2=sc.next().charAt(0);
n=sc.nextLong();
if(c1=='^'){
x=1;
}
if(c1=='^'){
x=1;
}
if(c1=='>'){
x=2;
}
if(c1=='v'){
x=3;
}
if(c1=='<'){
x=4;
}
if(c2=='^'){
y=1;
}
if(c2=='>'){
y=2;
}
if(c2=='v'){
y=3;
}
if(c2=='<'){
y=4;
}
z=n%4;
if(z==0){
z=4;
}
if((x==y && n==0) || (x==y && n%4==0)){
System.out.println("undefined");
}
else if((x-y==2 || y-x==2) && n%4==2){
System.out.println("undefined");
}
else if(x-y==z || 4+x-y==z){
System.out.println("ccw");
}
else{
System.out.println("cw");
}
}
} | JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | # problem/834/A
start, end = [str(n) for n in input().split(" ")]
n = int(input())
offset_cw = {'^':0, '>':1, 'v':2, '<':3}
offset_ccw = {'^':0, '<':1, 'v':2, '>':3}
def check(start, end, n, dict):
start_n = dict[start]
end_n = dict[end]
if (start_n + n) % 4 == end_n:
return True
else:
return False
cw = check(start, end, n, offset_cw)
ccw = check(start, end, n, offset_ccw)
if cw and not ccw:
print("cw")
elif ccw and not cw:
print("ccw")
else:
print("undefined")
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | cw={'v':0,'<':1,'^':2,'>':3}
a,b=raw_input().split()
n=input()
if n%2==1:
if (cw[a]+n)%4==cw[b]:
print 'cw'
else:
print 'ccw'
else:
print 'undefined' | PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
string a = "<^>v<^>v", b = "<v>^<v>^";
char x, y;
int n, f1, f2;
bool ans1, ans2;
int main() {
cin >> x >> y >> n;
n %= 4;
f1 = a.find(x);
f2 = b.find(x);
if (a[f1 + n] == y) ans1 = 1;
if (b[f2 + n] == y) ans2 = 1;
if (ans1 && ans2)
cout << "undefined\n";
else
cout << (ans1 ? "cw\n" : "ccw\n");
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const int N = 4 + 10;
char cw[N], ccw[N];
int main() {
char st, en;
int n;
cin >> st >> en >> n;
cw[0] = st;
ccw[0] = st;
for (int i = 1; i < 4; i++) {
if (cw[i - 1] == '^')
cw[i] = '>';
else if (cw[i - 1] == '>')
cw[i] = 'v';
else if (cw[i - 1] == 'v')
cw[i] = '<';
else
cw[i] = '^';
if (ccw[i - 1] == '^')
ccw[i] = '<';
else if (ccw[i - 1] == '<')
ccw[i] = 'v';
else if (ccw[i - 1] == 'v')
ccw[i] = '>';
else
ccw[i] = '^';
}
int ans = 0;
if (cw[n % 4] == en) ans++;
if (ccw[n % 4] == en) ans += 2;
if (ans == 1)
cout << "cw" << endl;
else if (ans == 2)
cout << "ccw" << endl;
else
cout << "undefined" << endl;
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | string = raw_input()
times = input()
vals = string.split(" ")
times = times % 4
# print times
mapping_cw={}
mapping_cw['^'] = '>'
mapping_cw['>'] = 'v'
mapping_cw['v'] = '<'
mapping_cw['<'] = '^'
mapping_ccw={}
mapping_ccw['^'] = '<'
mapping_ccw['>'] = '^'
mapping_ccw['v'] = '>'
mapping_ccw['<'] = 'v'
f_cw = 0
f_ccw = 0
prev1 = vals[0]
while f_ccw < times :
prev1 = mapping_ccw[prev1]
f_ccw= f_ccw + 1
prev2 = vals[0]
while f_cw < times :
prev2 = mapping_cw[prev2]
f_cw= f_cw + 1
if prev1 == vals[1] and prev2 == vals[1]:
print "undefined"
elif f_ccw==times and prev1 == vals[1]:
print "ccw"
else :
print "cw"
| PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
char x, y;
int n;
int main() {
char a[120];
a[0] = 118;
a[1] = 60;
a[2] = 94;
a[3] = 62;
a[4] = 118;
a[5] = 60;
a[6] = 94;
a[7] = 62;
cin >> x >> y >> n;
if ((n % 4) == 0) {
cout << "undefined" << endl;
return 0;
}
if (x == a[0] && y == a[2]) {
cout << "undefined" << endl;
return 0;
}
if (x == a[2] && y == a[0]) {
cout << "undefined" << endl;
return 0;
}
if (x == a[1] && y == a[3]) {
cout << "undefined" << endl;
return 0;
}
if (x == a[3] && y == a[1]) {
cout << "undefined" << endl;
return 0;
}
if ((int)x == 118 && n % 4 == 1) {
if (y == a[1]) {
cout << "cw" << endl;
return 0;
} else {
cout << "ccw" << endl;
return 0;
}
}
if ((int)x == 118 && n % 4 == 3) {
if (y == a[3]) {
cout << "cw" << endl;
return 0;
} else {
cout << "ccw" << endl;
return 0;
}
}
if ((int)x == 60 && n % 4 == 1) {
if (y == a[2]) {
cout << "cw" << endl;
return 0;
} else {
cout << "ccw" << endl;
return 0;
}
}
if ((int)x == 60 && n % 4 == 3) {
if (y == a[0]) {
cout << "cw" << endl;
return 0;
} else {
cout << "ccw" << endl;
return 0;
}
}
if ((int)x == 94 && n % 4 == 1) {
if (y == a[3]) {
cout << "cw" << endl;
return 0;
} else {
cout << "ccw" << endl;
return 0;
}
}
if ((int)x == 94 && n % 4 == 3) {
if (y == a[1]) {
cout << "cw" << endl;
return 0;
} else {
cout << "ccw" << endl;
return 0;
}
}
if ((int)x == 62 && n % 4 == 1) {
if (y == a[0]) {
cout << "cw" << endl;
return 0;
} else {
cout << "ccw" << endl;
return 0;
}
}
if ((int)x == 62 && n % 4 == 3) {
if (y == a[2]) {
cout << "cw" << endl;
return 0;
} else {
cout << "ccw" << endl;
return 0;
}
}
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | fr, ls = input().split()
n = int(input())
n %= 4
if n == 1:
if fr == '^':
if ls == '>':
print('cw')
else:
print('ccw')
if fr == '>':
if ls == '^':
print('ccw')
else:
print('cw')
if fr == 'v':
if ls == '>':
print('ccw')
else:
print('cw')
if fr == '<':
if ls == '^':
print('cw')
else:
print('ccw')
exit()
if n == 3:
if fr == '^':
if ls == '<':
print('cw')
else:
print('ccw')
if fr == '>':
if ls == '^':
print('cw')
else:
print('ccw')
if fr == 'v':
if ls == '>':
print('cw')
else:
print('ccw')
if fr == '<':
if ls == '^':
print('ccw')
else:
print('cw')
exit()
print('undefined') | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | b,e=input().split()
n=int(input())
n=n%4
if n==0:
print('undefined')
else:
cw='v<^>v<^>'
ccw='v>^<v>^<'
i1=cw.find(b)
i2=cw.find(e,i1+1)
j1=ccw.find(b)
j2=ccw.find(e,j1+1)
if i2-i1==n and j2-j1==n:
print('undefined')
elif i2-i1==n:
print('cw')
elif j2-j1==n:
print('ccw') | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | fwd=["v","<","^",">"]
bck=fwd[::-1]
f,s=input().split()
n=int(input())%4
fwdp=fwd.index(f)
bckp=bck.index(f)
a1,a2=fwd[(fwdp+n)%4],bck[(bckp+n)%4]
if a1==a2==s:print("undefined")
elif a1==s:print("cw")
else:print("ccw")
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 |
if __name__ == '__main__':
firstLine = raw_input()
positions = [x for x in firstLine.split()]
possiblePositions = {'v':0,'<':1,'^':2,'>':3}
timeTwisting = int(raw_input())
startingPosition = possiblePositions[positions[0]]
endingPosition =possiblePositions[positions[1]]
if (startingPosition + timeTwisting)%4 == endingPosition:
if (startingPosition - timeTwisting)%4 == endingPosition:
print "undefined"
else:
print "cw"
else:
print "ccw" | PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
string A, B;
int n, f1, f2, f3, f4;
cin >> A >> B;
cin >> n;
n = n % 4;
if (A == "v") f1 = 1;
if (A == "<") f1 = 2;
if (A == "^") f1 = 3;
if (A == ">") f1 = 4;
if (B == "v") f2 = 1;
if (B == "<") f2 = 2;
if (B == "^") f2 = 3;
if (B == ">") f2 = 4;
int cnt = f1;
for (int i = 1; i <= n; i++) {
if (cnt + 1 > 4)
cnt = 1;
else
cnt++;
}
int fl = 0, fl1 = 0;
if (cnt == f2) fl = 1;
cnt = f1;
for (int i = 1; i <= n; i++) {
if (cnt - 1 < 1)
cnt = 4;
else
cnt--;
}
if (cnt == f2) fl1 = 1;
if (fl1 == 1 && fl == 1) cout << "undefined" << endl;
if (fl == 1 && fl1 == 0) cout << "cw" << endl;
if (fl == 0 && fl1 == 1) cout << "ccw" << endl;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.util.*;
import java.io.*;
import java.math.*;
public class loser
{
static class InputReader {
public BufferedReader br;
public StringTokenizer token;
public InputReader(InputStream stream)
{
br=new BufferedReader(new InputStreamReader(stream),32768);
token=null;
}
public String next()
{
while(token==null || !token.hasMoreTokens())
{
try
{
token=new StringTokenizer(br.readLine());
}
catch(IOException e)
{
throw new RuntimeException(e);
}
}
return token.nextToken();
}
public int nextInt()
{
return Integer.parseInt(next());
}
public long nextLong()
{
return Long.parseLong(next());
}
}
static class card{
int l;
int r;
public card(int ch,int i)
{
this.l=ch;
this.r=i;
}
}
static class sort implements Comparator<card>
{
public int compare(card o1,card o2)
{
if(o1.l!=o2.l)
return (int)(o1.l-o2.l);
else
return (int)(o1.r-o2.r);
}
}
static void shuffle(long a[])
{
List<Long> l=new ArrayList<>();
for(int i=0;i<a.length;i++)
l.add(a[i]);
Collections.shuffle(l);
for(int i=0;i<a.length;i++)
a[i]=l.get(i);
}
/*static long gcd(long a,long b)
{
if(b==0)
return a;
else
return gcd(b,a%b);
}
static int ans1=Integer.MAX_VALUE,ans2=Integer.MAX_VALUE,ans3=Integer.MAX_VALUE,ans4=Integer.MAX_VALUE;
static boolean v[]=new boolean[101];
static void dfs(Integer so,Set<Integer> s[]){
if(!v[so.intValue()])
{
v[so]=true;
for(Integer h:s[so.intValue()])
{
if(!v[h.intValue()])
dfs(h,s);
}
}
}
static class Print{
public PrintWriter out;
Print(OutputStream o)
{
out=new PrintWriter(o);
}
}
static int CeilIndex(int A[], int l, int r, int key)
{
while (r - l > 1) {
int m = l + (r - l) / 2;
if (A[m] >= key)
r = m;
else
l = m;
}
return r;
}
static int LongestIncreasingSubsequenceLength(int A[], int size)
{
// Add boundary case, when array size is one
int[] tailTable = new int[size];
int len; // always points empty slot
tailTable[0] = A[0];
len = 1;
for (int i = 1; i < size; i++) {
if (A[i] < tailTable[0])
// new smallest value
tailTable[0] = A[i];
else if (A[i] > tailTable[len - 1])
// A[i] wants to extend largest subsequence
tailTable[len++] = A[i];
else
// A[i] wants to be current end candidate of an existing
// subsequence. It will replace ceil value in tailTable
tailTable[CeilIndex(tailTable, -1, len - 1, A[i])] = A[i];
}
return len;
}*/
/*static int binary(int n)
{
int s=1;
while(n>0)
{
s=s<<1;
n--;
}
return s-1;
}
static StringBuilder bin(int i,int n)
{
StringBuilder s=new StringBuilder();
while(i>0)
{
s.append(i%2);
i=i/2;
}
while(s.length()!=n)
{
s.append(0);
}
return s.reverse();
}*/
public static void main(String[] args)
{
InputReader sc=new InputReader(System.in);
Map<Character,Integer> m1=new HashMap<>();
Map<Character,Integer> m2=new HashMap<>();
m1.put('v',0);
m1.put('<',1);
m1.put('^',2);
m1.put('>',3);
char a[]={'v','<','^','>'};
char b[]={'v','>','^','<'};
m2.put('v',0);
m2.put('>',1);
m2.put('^',2);
m2.put('<',3);
char c[]=new char[2];
c[0]=sc.next().charAt(0);
c[1]=sc.next().charAt(0);
long n=sc.nextLong();
int n1=(int)(n%4);
int in1=m1.get(c[0]);
char cw=a[(in1+n1)%4];
int in2=m2.get(c[0]);
char ccw=b[(in2+n1)%4];
if(cw==c[1] && ccw==c[1])
System.out.println("undefined");
else if(cw==c[1])
System.out.println("cw");
else
System.out.println("ccw");
}
} | JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int Ch(char c) {
if (c == '^') {
return 0;
}
if (c == '>') {
return 1;
}
if (c == 'v') {
return 2;
}
if (c == '<') {
return 3;
}
}
int main() {
char c1, c2;
cin >> c1 >> c2;
int n, pos1 = Ch(c1), pos2 = Ch(c2);
cin >> n;
n = n % 4;
if (pos1 == pos2 || abs(pos1 - pos2) == 2) {
cout << "undefined";
return 0;
}
if ((pos1 + n) % 4 == pos2) {
cout << "cw";
} else {
cout << "ccw";
}
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | x=['<','^','>','v']
def get(k): #int
return x[k%4]
def find(k): #str
for i in range(4):
if x[i]==k:return i
def main(a,b,c): #str,str int
w=find(a)
q=get(w+c)
o=get(-c+w)
if q==b and o!=b:return "cw"
elif q!=b and o==b:return "ccw"
else:return "undefined"
g=raw_input().split()
l=input()
print main(g[0],g[1],l) | PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | //package year;
import java.io.*;
import java.util.*;
public class prac {
static PrintWriter out=new PrintWriter(System.out);
public static void main(String[] args) {
InputReader in=new InputReader(System.in);
String str=in.readString();
String str2=in.readString();
//System.out.println(str+" "+str2);
int n=in.nextInt();
boolean cc=false;
boolean cw=false;
int s=0;
int e=0;
if((int)str.charAt(0)==118){
s=0;
}
if((int)str.charAt(0)==60){
s=1;
}
if((int)str.charAt(0)==94){
s=2;
}
if((int)str.charAt(0)==62){
s=3;
}if((int)str2.charAt(0)==118){
e=0;
}
if((int)str2.charAt(0)==60){
e=1;
}if((int)str2.charAt(0)==94){
e=2;
}if((int)str2.charAt(0)==62){
e=3;
}
if((s+n)%4==e)
cc=true;
if((e+n)%4==s){
cw=true;
}
//System.out.println(s+" "+e);
if(cc&&cw){
System.out.println("undefined");
return;
}
else{
if(cc){
System.out.println("cw");
return;
}
if(cw)
{ System.out.println("ccw");
return;
}
System.out.println("undefined");
}
out.close();
}
//out.println(t);
public static class InputReader {
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
public InputReader(InputStream st) {
this.stream = st;
}
public int read() {
/* internless */
if (snumChars == -1)
throw new InputMismatchException();
if (curChar >= snumChars) {
curChar = 0;
try {
snumChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (snumChars <= 0)
return -1;
}
return buf[curChar++];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public double nextDouble() {
String doub = readString();
return Double.parseDouble(doub);
}
public float nextFloat() {
String doub = readString();
return Float.parseFloat(doub);
}
public long nextLong() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int[] sieve(int n) {
int ar[] = new int[n + 1];
ar[0] = 0;
ar[1] = 1;
for (int i = 2; i < ar.length; i++) {
if (ar[i] == 0) {
for (int k = i; k < ar.length; k = k + i) {
if (ar[k] == 0) {
ar[k] = i;
}
}
}
}
return ar;
}
public int[] nextIntArray(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
public Long[] nextLongArray(int n) {
Long a[] = new Long[n];
for (int i = 0; i < n; i++) {
a[i] = nextLong();
}
return a;
}
public ArrayList<ArrayList<Integer>> initlist(int n) {
ArrayList<ArrayList<Integer>> list = new ArrayList<>();
for (int i = 0; i <= n; i++) {
list.add(new ArrayList<Integer>());
}
return list;
}
public int[] initdp(int n) {
int ar[] = new int[n];
for (int i = 0; i < n; i++) {
ar[i] = -1;
}
return ar;
}
public int[][] initdp(int n, int m) {
int ar[][] = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++)
ar[i][j] = -1;
}
return ar;
}
public char[] constring(String str) {
char[] ar = new char[str.length()];
for (int i = 0; i < str.length(); i++) {
ar[i] = str.charAt(i);
}
return ar;
}
public static long gcd(long a, long b) {
a = Math.abs(a);
b = Math.abs(b);
while (b != 0) {
long temp = a % b;
a = b;
b = temp;
}
return a;
}
public static int longCompare(long a, long b) {
if (a < b) {
return -1;
}
if (a > b) {
return 1;
}
return 0;
}
public String readString() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public String nextLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | s, e = raw_input().split(" ")
n = input()%4
d = ["^", ">", "v", "<"]
s = d.index(s)
e = d.index(e)
if (s+n)%4==e and (s-n+4)%4==e:
print "undefined"
elif (s+n)%4==e:
print "cw"
else:
print "ccw" | PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | def check(d,f):
if d==f[0]:
if n%4==1:
return f[1]
elif n%4==2:
return f[2]
elif n%4==3:
return f[3]
else:
return f[0]
elif d==f[1]:
if n%4==1:
return f[2]
elif n%4==2:
return f[3]
elif n%4==3:
return f[0]
else:
return f[1]
elif d==f[2]:
if n%4==1:
return f[3]
elif n%4==2:
return f[0]
elif n%4==3:
return f[1]
else:
return f[2]
elif d==f[3]:
if n%4==1:
return f[0]
elif n%4==2:
return f[1]
elif n%4==3:
return f[2]
else:
return f[3]
s=list(map(str,input().split()))
n=int(input())
arr=['^','>','v','<']
arr1=['^','<','v','>']
a=check(s[0],arr)
b=check(s[0],arr1)
if a==b:
print("undefined")
elif a==s[1]:
print('cw')
elif b==s[1]:
print('ccw')
else:
print('undefined') | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
char a = sc.next().charAt(0);
char b = sc.next().charAt(0);
int n = sc.nextInt();
boolean first = (getIndex(a) + n % 4) % 4 == getIndex(b);
boolean second = (getIndex(a) + 4 - n % 4) % 4 == getIndex(b);
if (first && !second) {
System.out.println("cw");
} else if (!first && second) {
System.out.println("ccw");
} else {
System.out.println("undefined");
}
}
private static int getIndex(char c) {
switch (c) {
case 'v':
return 0;
case '<':
return 1;
case '^':
return 2;
case '>':
return 3;
default:
return 0;
}
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | start, end = input().split()
n = int(input())
n %= 4
map = {"^": 0, ">": 1, "v": 2, "<": 3}
start = map[start]
end = map[end]
if not n % 2:
print("undefined")
elif (start + n) % 4 == end:
print("cw")
else:
print("ccw")
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | cw = ['^', '>', 'v', '<']
ccw = ['^', '<', 'v', '>']
start , end = raw_input().split()
n = int(raw_input())
n = n % 4
a = cw.index(end) - cw.index(start)
b = ccw.index(end) - ccw.index(start)
if a<0:
a+=4
if b<0:
b+=4
if a==b:
print "undefined"
elif a == n:
print "cw"
else:
print "ccw"
| PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.io.*;
import java.util.*;
import java.math.*;
import java.util.concurrent.*;
public final class round_426_a
{
static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
static FastScanner sc=new FastScanner(br);
static PrintWriter out=new PrintWriter(System.out);
static Random rnd=new Random();
static char[] a=new char[]{'v','<','^','>'};
static int get(char ch)
{
for(int i=0;i<4;i++)
{
if(a[i]==ch)
{
return i;
}
}
return -1;
}
public static void main(String args[]) throws Exception
{
char c1=sc.next().charAt(0),c2=sc.next().charAt(0);
int n=sc.nextInt();
int pos1=get(c1);
int ptr1=pos1,val1=n%4;
while(val1>0)
{
ptr1--;
if(ptr1<0)
{
ptr1=3;
}
val1--;
}
int ptr2=pos1,val2=n%4;
while(val2>0)
{
ptr2++;
if(ptr2>3)
{
ptr2=0;
}
val2--;
}
if(a[ptr1]==a[ptr2] || (a[ptr1]!=c2 && a[ptr2]!=c2))
{
out.println("undefined");
}
else if(a[ptr2]==c2)
{
out.println("cw");
}
else
{
out.println("ccw");
}
out.close();
}
}
class FastScanner
{
BufferedReader in;
StringTokenizer st;
public FastScanner(BufferedReader in) {
this.in = in;
}
public String nextToken() throws Exception {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(in.readLine());
}
return st.nextToken();
}
public String next() throws Exception {
return nextToken().toString();
}
public int nextInt() throws Exception {
return Integer.parseInt(nextToken());
}
public long nextLong() throws Exception {
return Long.parseLong(nextToken());
}
public double nextDouble() throws Exception {
return Double.parseDouble(nextToken());
}
} | JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
char F, E, G;
int n;
cin >> F;
cin >> E;
cin >> n;
for (int x = 1; x <= n; x++) {
switch (F) {
case 94:
F = 62;
break;
case 62:
F = 'v';
break;
case 'v':
F = 60;
break;
case 60:
F = 94;
break;
}
}
if (n % 2 == 0) {
cout << "undefined";
} else if (F == E) {
cout << "cw";
} else {
cout << "ccw";
}
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | from itertools import cycle
begin, end = input().split()
n = int(input())%4
answer = "undefined"
if n != 0:
clockwise = cycle("^>v<")
counter_clockwise = cycle("^<v>")
current_cw = next(clockwise)
current_ccw = next(counter_clockwise)
while current_cw != begin:
current_cw = next(clockwise)
while current_ccw != begin:
current_ccw = next(counter_clockwise)
for i in range(n):
current_cw = next(clockwise)
current_ccw = next(counter_clockwise)
if current_cw != current_ccw == end:
answer = "ccw"
elif end == current_cw != current_ccw:
answer = "cw"
print(answer)
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | a = ['v', '<', '^', '>']
s, e = input().split()
n = int(input())
l = a.index(s)
r = l
n = n % 4
for i in range(n):
if l == 0: l = 3
else: l -= 1
if r == 3: r = 0
else: r += 1
if a[l] == e and a[r] == e:
print('undefined')
elif a[l] == e:
print('ccw')
elif a[r] == e:
print('cw') | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
char pos[4] = {'v', '<', '^', '>'};
char a, b;
int dur;
cin >> a >> b >> dur;
int index = -1;
if (a == 'v') {
index = 0;
} else if (a == '<') {
index = 1;
} else if (a == '^') {
index = 2;
} else {
index = 3;
}
bool cw = false;
bool ccw = false;
if (pos[(index + dur) % 4] == b) {
cw = true;
}
if (pos[((index - (dur % 4) + 4)) % 4] == b) {
ccw = true;
}
if (ccw && cw) {
cout << "undefined"
<< "\n";
} else if (cw) {
cout << "cw"
<< "\n";
} else {
cout << "ccw"
<< "\n";
}
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | d, s, n = '^>v<', input(), int(input())
if n % 2 == 0:
print('undefined')
elif (d.find(s[0]) + n) % 4 == d.find(s[2]):
print('cw')
else:
print('ccw')
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class toy {
public static PrintWriter out;
//-----------MyScanner class for faster input----------
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String args[]) throws Exception {
class prob {
public void solve() {
MyScanner sc = new MyScanner();
String in = "^>v<";
String x = sc.next();
//x += sc.next();
x += sc.next();
int sec = sc.nextInt();
sec = (sec % 4);
if ((sec % 2) == 0) {
System.out.println("undefined");
return;
}
int idx1 = in.indexOf(x.charAt(0));
int idx2 = in.indexOf(x.charAt(1));
int delta = (idx2 - idx1 + 4) % 4;
System.out.println(delta == sec ? "cw": "ccw");
}
}
prob s = new prob();
s.solve();
}
} | JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | '''input
mnbvcxzlkjhgfdsapoiuytrewq
asdfghjklqwertyuiopzxcvbnm
7abaCABAABAcaba7
'''
a = ['^','>','v','<']
s,e = map(str,raw_input().split())
n = int(raw_input())
k = a.index(s)
cw = (k+n)%4
acw = (k-n)%4
if a[cw] == e and a[acw] != e:
print "cw"
elif a[cw] != e and a[acw] == e:
print "ccw"
else:
print "undefined"
| PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
String str = br.readLine();
int n = Integer.parseInt(br.readLine());
n %= 4;
if(n == 2 || n == 0){
System.out.print("undefined");
return;
}
//System.out.println(str.length());
char array[] = new char[]{'^', '>','v' ,'<'};
for(int i = 0;i < array.length;i++){
if(str.charAt(0) == array[i]){
int curr = i;
while(n > 0){
++curr;
curr %= 4;
--n;
}
//System.out.println(curr + " " + array[curr] + " " + str.charAt(1));
if(array[curr] == str.charAt(2)){
System.out.println("cw");
}
else System.out.print("ccw");
}
}
}
} | JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
signed main(void) {
char s, f;
cin >> s >> f;
int n;
cin >> n;
n %= 4;
int ss, ff;
if (s == '^')
ss = 0;
else if (s == '>')
ss = 1;
else if (s == 'v')
ss = 2;
else if (s == '<')
ss = 3;
if (f == '^')
ff = 0;
else if (f == '>')
ff = 1;
else if (f == 'v')
ff = 2;
else if (f == '<')
ff = 3;
if ((ss + n) % 4 == ff && (ss - n + 4) % 4 == ff)
cout << "undefined" << endl;
else if ((ss + n) % 4 == ff)
cout << "cw" << endl;
else if ((ss - n + 4) % 4 == ff)
cout << "ccw" << endl;
else
cout << "undefined" << endl;
return 0;
}
| CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.