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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.lang.reflect.Array; import java.util.*; public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); Task solver = new Task(); solver.solve(in, out); out.close(); } } class Task { // static int MAX = 1000001; // List<List<Integer>> g = new ArrayList<>(); // int n; // char[] s; public void solve(Scanner in, PrintWriter out) { String s = in.next(); String[] ss = s.split("\\s++"); String[] arr = {"v", "<", "^", ">"}; List<String> strings = Arrays.asList(arr); int n = in.nextInt(); int x = (n % 4); if (x == 0 || x == 2) { System.out.println("undefined"); } else if ((strings.indexOf(ss[0]) + x) % 4 == strings.indexOf(ss[1])) { System.out.println("cw"); } else { System.out.println("ccw"); } } } class Utils { public static int binarySearch(int[] a, int key) { int s = 0; int f = a.length; while (f > s) { int mid = (s + f) / 2; if (a[mid] > key) { f = mid - 1; } else if (a[mid] <= key) { s = mid + 1; } } return -1; } public static long gcd(long a, long b) { return b != 0 ? gcd(b, a % b) : a; } public static long lcm(long a, long b) { return a / gcd(a, b) * b; } static List<Integer> prime(int number) { List<Integer> a = new ArrayList<>(); for (int i = 2; i * i <= number; i++) { if (number % i == 0) { a.add(i); number /= i; i = 1; } } a.add(number); return a; } } class Pair<T, U> { public T a; public U b; public Pair(T a, U b) { this.a = a; this.b = b; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Pair<?, ?> pair = (Pair<?, ?>) o; if (a != null ? !a.equals(pair.a) : pair.a != null) return false; return b != null ? b.equals(pair.b) : pair.b == null; } @Override public int hashCode() { int result = a != null ? a.hashCode() : 0; result = 31 * result + (b != null ? b.hashCode() : 0); return result; } } class Vect { public int a; public int b; public Vect(int a, int b) { this.a = a; this.b = b; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Vect vect = (Vect) o; if (a != vect.a) return false; return b == vect.b; } @Override public int hashCode() { int result = a; result = 31 * result + b; return result; } } class Tri { public int a; public int b; public int c; public Tri(int a, int b, int c) { this.a = a; this.b = b; this.c = c; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Tri tri = (Tri) o; if (a != tri.a) return false; return b == tri.b; } @Override public int hashCode() { int result = a; result = 31 * result + b; return result; } } class Triple<T, U, P> { public T a; public U b; public P c; public Triple(T a, U b, P c) { this.a = a; this.b = b; this.c = c; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Triple<?, ?, ?> triple = (Triple<?, ?, ?>) o; if (a != null ? !a.equals(triple.a) : triple.a != null) return false; return b != null ? b.equals(triple.b) : triple.b == null; } @Override public int hashCode() { int result = a != null ? a.hashCode() : 0; result = 31 * result + (b != null ? b.hashCode() : 0); return result; } } class Scanner { BufferedReader in; StringTokenizer tok; public Scanner(InputStream in) { this.in = new BufferedReader(new InputStreamReader(in)); tok = new StringTokenizer(""); } private String tryReadNextLine() { try { return in.readLine(); } catch (Exception e) { throw new InputMismatchException(); } } public String nextToken() { while (!tok.hasMoreTokens()) { tok = new StringTokenizer(next()); } return tok.nextToken(); } public String next() { String newLine = tryReadNextLine(); if (newLine == null) throw new InputMismatchException(); return newLine; } public int nextInt() { return Integer.parseInt(nextToken()); } public long nextLong() { return Long.parseLong(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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; char pos[] = {'v', '<', '^', '>'}; char ctpos[] = {'v', '>', '^', '<'}; char rotate(char s, int n, char pos[]) { int p = 0; while (pos[p] != s) p += 1; n = n % 4; char r = pos[(p + n) % 4]; return r; } int main() { char s, t; scanf("%c %c\n", &s, &t); int n; scanf("%d", &n); bool iscw = rotate(s, n, pos) == t; bool isccw = rotate(s, n, ctpos) == t; if (iscw && isccw) cout << "undefined" << endl; else if (iscw) 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int main() { char arr[2]; cin >> arr[0]; cin >> arr[1]; long long int n; cin >> n; if ((arr[0] == '^' && arr[1] == '>') || (arr[0] == 'v' && arr[1] == '<') || (arr[0] == '<' && arr[1] == '^') || (arr[0] == '>' && arr[1] == 'v')) { if (n % 4 == 1) cout << "cw"; else if (n % 4 == 3) cout << "ccw"; else cout << "undefined"; } else if ((arr[0] == '^' && arr[1] == '<') || (arr[0] == 'v' && arr[1] == '>') || (arr[0] == '<' && arr[1] == 'v') || (arr[0] == '>' && arr[1] == '^')) { if (n % 4 == 3) cout << "cw"; else if (n % 4 == 1) cout << "ccw"; else cout << "undefined"; } 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#problem66 a,b = map(str,input().split()) c = int(input()) toy = 'v<^>' if c%2==0: print('undefined') elif (toy.find(a)+c)%4 == toy.find(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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
DIRS = ['v', '<', '^', '>'] a, b = map(DIRS.index, input().split()) n = int(input()) delta = (b - a + 4) % 4 if delta == 0 or delta == 2: print('undefined') elif delta == n % 4: print('cw') else: print('ccw') 1
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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
s = [chr(118),chr(60),chr(94),chr(62)] a,b = raw_input().split() a1 = s.index(a) b1 = s.index(b) n = input() a2 = (a1-b1)%4 b2 = (b1-a1)%4 c = n%4 if a2==c and b2<>c: print 'ccw' elif a2<>c and b2==c: print 'cw' 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
le, ri = raw_input().split() N = input() % 4 def rotate(a, n, direc): while n > 0: n -= 1 if direc == 'cw': if a == '<': a = '^' elif a == '^': a = '>' elif a == '>': a = 'v' elif a == 'v': a = '<' else: if a == '<': a = 'v' elif a == '^': a = '<' elif a == '>': a = '^' elif a == 'v': a = '>' return a if rotate(le, N, 'cw') == rotate(le, N, 'ccw'): print 'undefined' elif rotate(le, N, 'cw') == ri: print 'cw' elif rotate(le, N, 'ccw') == ri: 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
spinner_cw = ['^', '>', 'v', '<'] spinner_ccw = ['^', '<', 'v', '>'] ip = input().split() start = ip[0] end = ip[1] n = int(input()) ix_cw = spinner_cw.index(start) ix_ccw = spinner_ccw.index(start) if spinner_cw[(ix_cw + n) % 4] == end and spinner_ccw[(ix_ccw + n) % 4] == end: print('undefined') elif spinner_cw[(ix_cw + 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int main() { char s[100]; int cnt = 0; int a[5]; for (int i = 0; i <= 10; i++) { char ch = getchar(); if (ch == 94) a[++cnt] = 1; if (ch == 62) a[++cnt] = 2; if (ch == 118) a[++cnt] = 3; if (ch == 60) a[++cnt] = 0; if (cnt == 2) break; } int d, ans = 0; scanf("%d", &d); if ((a[1] + d) % 4 == a[2]) ans++; if ((a[2] + d) % 4 == a[1]) ans--; if (ans == 1) printf("cw\n"); else if (ans == -1) printf("ccw\n"); else if (ans == 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int n, m, tr[300]; char s[3], t[3]; int main() { scanf("%s%s%d", s, t, &n); n %= 4; tr['v'] = 0; tr['<'] = 1; tr['^'] = 2; tr['>'] = 3; if (n & 1 ^ 1) puts("undefined"); else puts((tr[s[0]] + n) % 4 == tr[t[0]] ? "cw" : "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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; string getSpinDirection(int start, int end, int spinCount) { string result = "undefined"; vector<int> rotor = {94, 62, 118, 60}; int start_index; for (int i = 0; i < 4; ++i) if (rotor[i] == start) { start_index = i; break; } if (spinCount % 2 == 0) return result; spinCount = spinCount % 4; if (rotor[(start_index + spinCount) % 4] == end) result = "cw"; else if (rotor[(start_index + (4 - spinCount)) % 4] == end) result = "ccw"; return result; } int main() { char start, end; int spinCount; cin >> start >> end; cin >> spinCount; cout << getSpinDirection(start, end, spinCount) << 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
a,b = raw_input().split() n = int(raw_input()) x = "v<^>" if a == b: print "undefined" elif set([a,b]) == set("<>"): print "undefined" elif set([a,b]) == set("^v"): print "undefined" else: r = x.index(a) if x[(r+n)%4] == b: 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.io.*; import java.util.*; public final class Main{ public static void main(String args[]){ Scanner in=new Scanner(System.in); String a=in.next(); String b=in.next(); int x=in.nextInt(); x=x%4; String s[]={"<","^",">","v"}; int pos=0; for(int i=0;i<4;i++){ if(s[i].equals(a)) pos=i; } int n=pos+x; if(n>=4) n=n-4; int m=pos-x; if(m<0) m+=4; if(b.equals(s[n]) && !b.equals(s[m])) System.out.println("cw"); else if(b.equals(s[m]) && !b.equals(s[n])) 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
a,b=map(str,input().split()) n=int(input()) c=["v","<","^",">","v","<","^",">"] d=["v",">","^","<","v",">","^","<"] if(n%4==1): for i in range(8): if(a==c[i]): if(b==c[i+1]): print("cw") break else: for i in range(8): if(a==d[i]): if(b==d[i+1]): print("ccw") break else: print("undefined") break break elif(n%4==3): for i in range(8): if(a==c[i]): if(b==c[i+3]): print("cw") break else: for i in range(8): if(a==d[i]): if(b==d[i+3]): print("ccw") break else: print("undefined") break break 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; const long long int N = 100005; int main() { ios::sync_with_stdio(false); long long int n; char a, b; char c[] = {'v', '<', '^', '>'}; cin >> a >> b >> n; n %= 4; if (n == 0) { cout << "undefined\n"; return 0; } long long int in; if (a == 'v') { in = 0; } else if (a == '<') { in = 1; } else if (a == '^') { in = 2; } else { in = 3; } long long int m = n; long long int in2 = in; while (n--) { in++; if (in == 4) { in = 0; } } long long int flag = 0; long long int flag2 = 0; if (c[in] == b) { flag = 1; } in = in2; while (m--) { in--; if (in == -1) { in = 3; } } if (c[in] == b) { flag2 = 1; } if (flag && flag2) { cout << "undefined\n"; } else if (flag) { 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 ^ &gt; 1 Output cw Input &lt; ^ 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.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; 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); OutputWriter out = new OutputWriter(outputStream); TaskA solver = new TaskA(); solver.solve(1, in, out); out.close(); } static class TaskA { public void solve(int testNumber, InputReader in, OutputWriter out) { char s = in.readCharacter(); char f = in.readCharacter(); int n = in.readInt() % 4; if (n == 0 || n == 2) { out.printLine("undefined"); } else { String beforeCW = "v<^>"; String afterCW = "<^>v"; for (int i = 0; i < n - 1; i++) { int idx = beforeCW.indexOf(s); s = afterCW.charAt(idx); } int idx = beforeCW.indexOf(s); if (afterCW.charAt(idx) == f) { out.printLine("cw"); } else { out.printLine("ccw"); } } } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } } public void printLine(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } } 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 readInt() { 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 boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public char readCharacter() { int c = read(); while (isSpaceChar(c)) { c = read(); } return (char) c; } 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.util.*; public class Works { static int[] a = {118,60,94,62}; public static void main(String[] args) { Scanner in = new Scanner(System.in); int first = in.next().charAt(0); int last = in.next().charAt(0); int n = in.nextInt(); int buff = n; String out = ""; int posFirst = findPos(first); int posLast = findPos(last); boolean cw = false; if ( n % 2 == 0 || posFirst - posLast == 2 || posFirst - posLast == -2) out = "undefined"; else { if ((posFirst + n) % 4 == posLast) out = "cw"; else out = "ccw"; } // if (posFirst - posLast == 2 || posFirst - posLast == -2 || posFirst - posLast == 0) out = "undefined"; // else { // int i = posFirst + 1; // while (n-- > 0) { // if (i > 3) i = 0; // if (a[i] == a[posLast] && n == 0) { // out = "cw"; // cw = true; // break; // } // i++; // } // i = posFirst - 1; // n = buff; // while (n-- > 0 && !cw) { // if (i < 0) i = 3; // if (a[i] == a[posLast] && n == 0) { // out = "ccw"; // break; // } // i--; // } // } // if (out.isEmpty()) out = "undefined"; System.out.println(out); } private static int findPos(int k) { for (int i = 0; i < a.length; i++) { if (a[i] == k) return i; } 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import sys aa,bb=raw_input().split() a=ord(aa) b=ord(bb) n=int(raw_input()) n=n%4 v=[118,60,94,62] i=0 while(v[i]!=a):i=i+1 ans=0 num=i+n if i+n<4 else (i+n)%4 if(v[num]==b): ans=1 num=i-n if i-n>=0 else (i-n+4)%4 if(v[num]==b): ans=ans+2 if(ans==1):print 'cw' elif(ans==2):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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#problem 834 A x,y=input().split() temp1=0 temp2=0 size=int(input()) list_cw=["^",">","v","<","^",">","v","<"] list_ccw=["^","<","v",">","^","<","v",">"] for i in range(0,5): if x==list_cw[i] and y==list_cw[i+(size%4)]: temp1=1 #print("checkpoint 1") if x==list_ccw[i] and y==list_ccw[i+(size%4)]: temp2=2 #print("checkpoint 2") else: #print("checkpoint 3") temp=0 if temp1==1 and temp2==2: print("undefined") elif temp1==1: 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int main() { map<char, long long> mp1, mp2; mp1['v'] = 1; mp1['<'] = 2; mp1['^'] = 3; mp1['>'] = 4; mp2['v'] = 1; mp2['>'] = 2; mp2['^'] = 3; mp2['<'] = 4; char a, b; long long n; cin >> a >> b; cin >> n; n = n % 4; long long one, two; one = (mp1[a] + n) % 4; if (one == 0) one = 4; two = (mp2[a] + n) % 4; if (two == 0) two = 4; long long f1 = 0, f2 = 0; if (one == mp1[b]) f1 = 1; if (two == mp2[b]) f2 = 1; if (f1 == 1 && f2 == 0) { cout << "cw" << endl; return 0; } else if (f1 == 0 && f2 == 1) { cout << "ccw" << endl; return 0; } 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import sys s = '^>v<' ch2int = {} for i, c in enumerate(s): ch2int[c] = i a, b, n = sys.stdin.read().split() a = ch2int[a]; b = ch2int[b]; n = int(n) iscw = (s[(a+n)%4] == s[b]) isccw = (s[(a-n)%4] == s[b]) if iscw and not isccw: print('cw') elif not iscw and isccw: 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
from sys import stdin, stdout d1,d2 = stdin.readline().rstrip().split() n = int(stdin.readline().rstrip()) direction = [] for x in [d1,d2]: if x=='^': direction.append(0) elif x=='>': direction.append(1) elif x=='<': direction.append(3) else: direction.append(2) n = n%4 lTrue = False rTrue = False if (direction[0]+n)%4==direction[1]: lTrue = True if (direction[0]-n)%4==direction[1]: rTrue = True if lTrue and rTrue: print("undefined") elif lTrue: 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> int main() { char s[10]; while (gets(s)) { int cn, ccn; if (s[0] == '<' && s[2] == '^' || s[0] == '^' && s[2] == '>' || s[0] == '>' && s[2] == 'v' || s[0] == 'v' && s[2] == '<') { cn = 1; ccn = 3; } else if (s[0] == '<' && s[2] == '>' || s[0] == '^' && s[2] == 'v' || s[0] == '>' && s[2] == '<' || s[0] == 'v' && s[2] == '^') { cn = 2; ccn = 2; } else if (s[2] == '<' && s[0] == '^' || s[2] == '^' && s[0] == '>' || s[2] == '>' && s[0] == 'v' || s[2] == 'v' && s[0] == '<') { cn = 3; ccn = 1; } int n; scanf("%d", &n); getchar(); n = n % 4; if (n == 2 || n == 0) printf("undefined\n"); else if (n == cn) printf("cw\n"); else 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); char c1, c2; cin >> c1 >> c2; long long n; cin >> n; vector<char> a1; a1.push_back('v'); a1.push_back('<'); a1.push_back('^'); a1.push_back('>'); vector<char> a2; a2.push_back('v'); a2.push_back('>'); a2.push_back('^'); a2.push_back('<'); n = n % 4; bool f1 = false, f2 = false; if (c1 == a1[0] && c2 == a1[n] || c1 == a1[1] && c2 == a1[(1 + n) % 4] || c1 == a1[2] && c2 == a1[(2 + n) % 4] || c1 == a1[3] && c2 == a1[(3 + n) % 4]) { f1 = true; } if (c1 == a2[0] && c2 == a2[n] || c1 == a2[1] && c2 == a2[(1 + n) % 4] || c1 == a2[2] && c2 == a2[(2 + n) % 4] || c1 == a2[3] && c2 == a2[(3 + n) % 4]) { f2 = true; } if (f1 && f2) { cout << "undefined"; } else if (f1) { 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
a = [i for i in input().split()] n = int(input()) ans = None pol = ["v", "<", "^", ">"] if pol[((pol.index(a[1]) + n) % 4)] == a[0]: ans = "ccw" if pol[((pol.index(a[1]) - n) % 4)] == a[0]: if ans != None: ans = "undefined" else: ans = "cw" 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int main() { char s[10]; char mid, star, fina; long long x, y, n, judge1, judge2; gets(s); star = s[0]; fina = s[2]; scanf("%lld", &n); judge1 = 0; judge2 = 0; if (star == 'v') x = 1; else if (star == '<') x = 2; else if (star == '^') x = 3; else if (star == '>') x = 4; if (fina == 'v') y = 1; else if (fina == '<') y = 2; else if (fina == '^') y = 3; else if (fina == '>') y = 4; long long temp = n % 4; long long xx = x + temp; if (xx > 4) xx -= 4; if (y == xx) judge1 = 1; if (x > temp) { if (y == x - temp) judge2 = 1; } else { long long tt = temp - x + 1; tt = 4 - tt + 1; if (tt == y) judge2 = 1; } if (judge1 && judge2) printf("undefined\n"); else if (judge1) printf("cw\n"); else 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
cs = raw_input().split(' ') t = int(raw_input()) start = "^>v<".find(cs[0]) end = "^>v<".find(cs[1]) cw = (start + t) % 4 == end ccw = (start - t) % 4 == end if cw and not ccw: print "cw" elif ccw and not cw: 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.util.*; public class MyClass { public static void main(String args[]) { Scanner scan = new Scanner(System.in); char r=scan.next().charAt(0),l=scan.next().charAt(0); int n=scan.nextInt(); char a [] = {'v','<','^','>'}; char b [] = {'v','>','^','<'}; int x=0,y=0; for (int i=0;i<4;i++){if(a[i]==r)x=i;if(b[i]==r)y=i;} if(n%2==0) System.out.print("undefined"); else if(a[(x+n%4)%4]==l)System.out.print("cw"); else if (b[(y+n%4)%4]==l)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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
// AUTHOR : MAYANK SUNAL import java.io.*; import java.util.*; import java.math.*; public class Main { static final Random random = new Random(); static PrintWriter out = new PrintWriter((System.out)); static Reader sc = new Reader(); public static void main(String args[]) throws IOException { // int t = sc.nextInt(); // while (t-- > 0) { // CODE START FROM HERE long n = sc.nextLong(); char a = sc.next().charAt(0); char b = sc.next().charAt(0); int n = sc.nextInt(); Integer arr[] = { 118, 60, 94, 62 }; int index = 0; for (int i = 0; i < 4; i++) if (arr[i] == (int) a) { index = i; break; } if (arr[(index + (n % 4)) % 4] == (int) b && arr[(4 + index - (n % 4)) % 4] == (int) b) System.out.println("undefined"); else if (arr[(4 + index - (n % 4)) % 4] == (int) b) System.out.println("ccw"); else if (arr[(index + (n % 4)) % 4] == (int) b) System.out.println("cw"); // } } // Fast Input Output static class Reader { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public String next() { while (!st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { e.printStackTrace(); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { try { return br.readLine(); } catch (Exception e) { e.printStackTrace(); } return null; } public boolean hasNext() { String next = null; try { next = br.readLine(); } catch (Exception e) { } if (next == null) { return false; } st = new StringTokenizer(next); return true; } } // EFFICIENT SORTING Ascending static void ruffleSortAsc(Integer[] a) { int n = a.length; // shuffle, then sort for (int i = 0; i < n; i++) { int oi = random.nextInt(n), temp = a[oi]; a[oi] = a[i]; a[i] = temp; } Arrays.sort(a); } // EFFICIENT SORTING Descending static void ruffleSortDesc(Integer[] a) { int n = a.length; // shuffle, then sort for (int i = 0; i < n; i++) { int oi = random.nextInt(n), temp = a[oi]; a[oi] = a[i]; a[i] = temp; } Arrays.sort(a, Collections.reverseOrder()); } // Array Sum static long sum(Integer[] arr) { long sum = 0; for (int i : arr) sum += i; return sum; } // ArrayList Sum static long sumal(ArrayList<Integer> al) { long sum = 0; for (int i : al) sum += i; return sum; } // swap array elements static void swap(int arr1[], int arr2[], int i, int j) { int temp = arr1[i]; arr1[i] = arr2[j]; arr2[j] = temp; } // reading array value; static void read(Integer[] arr) { for (int i = 0; i < arr.length; i++) arr[i] = sc.nextInt(); return; } // reading arraylistValue static void readal(List<Integer> l, int n) { for (int i = 0; i < n; i++) l.add(sc.nextInt()); return; } // check for even odd static boolean isEven(long n) { return ((n & 1) != 1); } // max in a array static int max(Integer[] arr) { int max = Integer.MIN_VALUE; for (int i = 0; i < arr.length; i++) if (max < arr[i]) max = arr[i]; return max; } // print array static void printarr(Integer arr[]) { for (int i : arr) System.out.println(i); } // ceil of two elements static int ceil(int a, int b) { return (int) Math.ceil(((double) a / (double) b)); } // floor of two elements static int floor(int a, int b) { return (int) Math.floor(((double) a / (double) b)); } }
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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.util.*; import java.io.*; public class The_Useless_Toy { public static void main(String args[]) throws Exception { BufferedReader f=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(f.readLine()); HashMap<String,Integer> map=new HashMap<String,Integer>(); map.put("<",0); map.put("^",1); map.put(">",2); map.put("v",3); String a=st.nextToken(); String b=st.nextToken(); int time=Integer.parseInt(f.readLine()); if(Math.abs(map.get(a)-map.get(b))==2||map.get(a)==map.get(b)) System.out.println("undefined"); else { time=time%4; if((map.get(b)-map.get(a)+4)%4==time) 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.util.*; public class TestClass { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String s=sc.nextLine(); char[] arr=new char[]{'^','>','v','<'}; char d1=s.charAt(0); char d2=s.charAt(2); int rotation=sc.nextInt()%4; int index=0; for(int i=1;i<=3;++i){ if(arr[i]==d1) index=i; } if(rotation==0 || rotation==2) System.out.println("undefined"); else if(rotation==1){ if(arr[(rotation+index)%4]==d2) System.out.println("cw"); else System.out.println("ccw"); } else{ if(arr[(rotation+index)%4]==d2) 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
start, final = map(str, raw_input().split()) duration = int(raw_input()) if start == final or start == 'v' and final == '^' or start == '^' and final == 'v' or start == '>' and final == '<' \ or start == '<' and final == '>': print("undefined") if start == 'v': if final == '>' and duration % 4 == 1 or final == '<' and duration % 4 == 3: print("ccw") elif final == '>' and duration % 4 == 3 or final == '<' and duration % 4 == 1: print("cw") elif start == '>': if final == 'v' and duration % 4 == 1 or final == '^' and duration % 4 == 3: print("cw") elif final == 'v' and duration % 4 == 3 or final == '^' and duration % 4 == 1: print("ccw") elif start == '^': if final == '>' and duration % 4 == 1 or final == '<' and duration % 4 == 3: print("cw") elif final == '>' and duration % 4 == 3 or final == '<' and duration % 4 == 1: print("ccw") elif start == '<': if final == 'v' and duration % 4 == 1 or final == '^' and duration % 4 == 3: print("ccw") elif final == 'v' and duration % 4 == 3 or final == '^' and duration % 4 == 1: 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; char a, b; char f[300], g[300]; int main() { int n; int i; cin >> a >> b; cin >> n; n %= 4; f['^'] = '>'; f['>'] = 'v'; f['v'] = '<'; f['<'] = '^'; g['^'] = '<'; g['<'] = 'v'; g['v'] = '>'; g['>'] = '^'; int sum = 0; int c = a; for (i = 1; i <= n; i++) { c = f[c]; } if (c == b) sum += 1; c = a; for (i = 1; i <= n; i++) c = g[c]; if (c == b) sum += 2; if (sum == 1) cout << "cw" << endl; else if (sum == 2) 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; map<char, int> mp; int n; int main() { mp['v'] = 0; mp['<'] = 1; mp['^'] = 2; mp['>'] = 3; char a, b; scanf("%c%*c%c", &a, &b); scanf("%d", &n); n %= 4; int tt = (mp[a] + n) % 4; int qq = (mp[a] + 4 - n) % 4; if (qq == mp[b] && tt == mp[b]) printf("undefined"); else if (tt == mp[b]) printf("cw"); else 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#Codeforces Round 426 #problem A def main(): cw_dir = '^>v<' ccw_dir = '^<v>' input1 = input() input2 = input() startPos = input1[0] endPos = input1[2] secs = int(input2) cw = False ccw = False output = 'undefined' if ((cw_dir.find(startPos) + secs) % 4) == (cw_dir.find(endPos)): cw = True #print(cw_dir.find(startPos)) if ((ccw_dir.find(startPos) + secs) % 4) == (ccw_dir.find(endPos)): ccw = True if cw != ccw: if cw: output = 'cw' else: output = 'ccw' print(output) if __name__ == '__main__': 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; char num[4] = {'v', '<', '^', '>'}; char num1[4] = {'v', '>', '^', '<'}; int main() { char a, b; long long n; while (cin >> a >> b >> n) { int temp1 = -1, temp2 = -1; for (int i = 0; i < 4; i++) { if (a == num[i]) { temp1 = i; } if (a == num1[i]) { temp2 = i; } } if (num[(temp1 + n) % 4] == b && num1[(temp2 + n) % 4] == b) { cout << "undefined" << endl; } else if (num1[(temp2 + n) % 4] == b) { cout << "ccw" << endl; } else if (num[(temp1 + n) % 4] == b) { cout << "cw" << 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#!/usr/bin/python from collections import deque def ir(): return int(raw_input()) d = raw_input(); f, t = d.split() n = ir(); n %= 4 D = 'v<^>' def pbc(k): n = len(D) if k < 0: return pbc(k + n) elif k >= n: return pbc(k - n) else : return k f = D.find(f); t = D.find(t) r = pbc(f + n) == t l = pbc(f - n) == t U = "undefined" R = "cw" L = "ccw" if r and l: print U elif r: print R elif l: print 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
a, b = input().split() n=int(input()) if a=="^": a1=1 elif a=="<": a1=2 elif a=="v": a1=3 elif a==">": a1=4 if b=="^": b1=1 elif b=="<": b1=2 elif b=="v": b1=3 elif b==">": b1=4 n=n%4 a2=a1-n a3=a1+n if a2<=0: a2=a2+4 if a3>4: a3=a3-4 if (b1==a2)&(b1!=a3): print("cw") elif (b1!=a2)&(b1==a3): 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using vi = vector<int>; using vvi = vector<vi>; using pii = pair<int, int>; const int MAXN = 1e5 + 5; const int MAXM = 1e5 + 5; const int MOD = 1e9 + 7; const int INF = 2e9; const ll LLINF = 2e18; const ld EPS = 1e-9; int m, n, k, ans, cnt, x, y, l, r; string s; char c1, c2; std::vector<char> ar = {'v', '<', '^', '>'}; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> c1 >> c2 >> n; n %= 4; if (n == 0 || n == 2) { cout << "undefined\n"; return 0; } int i = 0; while (ar[i] != c1) { i++; } for (int j = 0; j < n; j++) { i++; if (i == 4) { i = 0; } } if (ar[i] == c2) { 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
x,y=input().split() n=int(input()) if(n%2==0): print('undefined') else: k=ord(x)-ord(y) if(n%4==1): if(k==58 or k==-34 or k==32 or k==-56): print('cw') else: print('ccw') else: if(k==-58 or k==34 or k==-32 or k==56): 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#!/usr/bin/env python3 from sys import stdin, stdout def rint(): return map(int, stdin.readline().split()) #lines = stdin.readlines() t = {'v':0, '<':1, '^':2, '>':3} a, b = map(str, input().split()) n = int(input()) n %= 4 if n == 0 or n == 2: print('undefined') exit() a, b = t[a], t[b] if b < a: b +=4 diff = b - a if n == 1: if diff == 1: print("cw") elif diff == 3: print("ccw") else: print('undefined') elif n == 3: if diff == 1: print("ccw") elif diff == 3: 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
# ################################################################# # This solution has been prepared for TheCodingConversations google # meet session to be held on 2020-09-06. If you wish to participate # in this session kindly refrain from reading this solution until # the session has been concluded. # # author - atifcppprogrammer # ################################################################# # 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()) # Moving in round-robin manner in both clock-wise and # counter-clockwise directions to see if spinner stops # at given ending position. isCCW = rotations['ccw'][start][ seconds % 4 ] == end isCW = rotations['cw'][start][ seconds % 4 ] == end # Printing 'ccw or 'cw' if one of the two rotations is # possible, printing 'undefined' if both or neither is # possible. 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; const string cw = "^>v<^>v<"; const string ccw = "^<v>^<v>"; void docfile() { ios::sync_with_stdio(false); cin.tie(nullptr); if (ifstream("test" ".inp")) { freopen( "test" ".inp", "r", stdin); freopen( "test" ".out", "w", stdout); } else if (ifstream("" ".inp")) { freopen( "" ".inp", "r", stdin); freopen( "" ".out", "w", stdout); } } void enter() { char c1, c2; int n; cin >> c1 >> c2; cin >> n; n %= 4; if (labs(cw.substr(cw.find(c1), cw.size()).find(c2)) == n && labs(ccw.substr(ccw.find(c1), ccw.size()).find(c2)) == n) cout << "undefined"; else if (labs(cw.substr(cw.find(c1), cw.size()).find(c2)) == n) cout << "cw"; else if (labs(ccw.substr(ccw.find(c1), ccw.size()).find(c2)) == n) cout << "ccw"; else cout << "undefined"; } void init() {} void solve() {} void print_result() {} int main() { docfile(); int t = 1; for (int tt = 0; tt < t; ++tt) { enter(); init(); solve(); print_result(); } }
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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
positions_input = input().split(' ') times = int(input()) positions = ['v','<','^','>'] i = times % 4 def fin_pos(idx, direction): global positions global i if direction == 'r': return positions[(idx + i)%4] elif direction == 'l': return positions[(idx - i)%4] idx = positions.index(positions_input[0]) if fin_pos(idx, 'r') == fin_pos(idx, 'l') == positions_input[1]: print('undefined') elif fin_pos(idx, 'r') == positions_input[1]: print('cw') # right elif fin_pos(idx, 'l') == positions_input[1]: print('ccw') # left
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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import sys a = input() b = int(input()) % 4 c = ord(a[0]) - ord(a[2]) d = {58: 'cw', 56: 'ccw', -58: 'ccw', -34: 'cw', 34: 'ccw', 32: 'cw', -56: 'cw', -32: 'ccw'} if b % 2 == 0: sys.stdout.write('undefined') else: if b == 1: sys.stdout.write(d[c]) else: sys.stdout.write(d[-c])
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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
a=raw_input().split(' ') n=int(raw_input()) if n%2 ==0 : print "undefined" elif n%4 == 3: if (a[0]=='^' and a[1]=='<') or (a[0]=='>' and a[1] == '^') or (a[0] == 'v' and a[1] == '>') or (a[0]=='<' and a[1]=='v') : print "cw" else : print "ccw" elif n%4==1: if (a[0]=='^' and a[1]=='>') or (a[0]=='>' and a[1] == 'v') or (a[0] == 'v' and a[1] == '<') or (a[0]=='<' and 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.io.*; import java.util.*; public class A { public static void main(String args[]) throws IOException{ Scanner sc = new Scanner(System.in); String full = sc.nextLine(); char f = full.charAt(0); char s = full.charAt(2); int n = sc.nextInt(); n=n%4; char[] arr = new char[4]; arr[0] = 118; arr[1] = 60; arr[2] = 94; arr[3] = 62; boolean cw = false; boolean ccw = false; for(int i = 0 ; i < 4 ; i++){ if (arr[i] == f){ if(arr[(i+n)%4] == s){ cw = true; } if(arr[(i-n + 4)%4] == s){ ccw = true; } } } if(cw && ccw){ System.out.println("undefined"); return; } if(cw){ System.out.println("cw"); } else if (ccw){ 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 ^ &gt; 1 Output cw Input &lt; ^ 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; int x = n / 4, y = n % 4; if (n % 4 == 2 || n % 4 == 0) { cout << "undefined" << endl; return 0; } else if (y == 1) { if (a == '^' && b == '>') cout << "cw" << endl; else if (a == '>' && b == 'v') cout << "cw" << endl; else if (a == 'v' && b == '<') cout << "cw" << endl; else if (a == '<' && b == '^') cout << "cw" << endl; else if (a == '^' && b == '<') cout << "ccw" << endl; else if (a == '>' && b == '^') cout << "ccw" << endl; else if (a == 'v' && b == '>') cout << "ccw" << endl; else if (a == '<' && b == 'v') cout << "ccw" << endl; } else if (y == 3) { if (a == '^' && b == '>') cout << "ccw" << endl; else if (a == '>' && b == 'v') cout << "ccw" << endl; else if (a == 'v' && b == '<') cout << "ccw" << endl; else if (a == '<' && b == '^') cout << "ccw" << endl; else if (a == '^' && b == '<') cout << "cw" << endl; else if (a == '>' && b == '^') cout << "cw" << endl; else if (a == 'v' && b == '>') cout << "cw" << endl; else if (a == '<' && b == 'v') cout << "cw" << 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int n; int a[500][500]; int b[500][500]; char stra[10]; char strb[10]; int main() { a['v']['v'] = 0; a['v']['<'] = 1; a['v']['^'] = 2; a['v']['>'] = 3; a['<']['v'] = 3; a['<']['<'] = 0; a['<']['^'] = 1; a['<']['>'] = 2; a['^']['v'] = 2; a['^']['<'] = 3; a['^']['^'] = 0; a['^']['>'] = 1; a['>']['v'] = 1; a['>']['<'] = 2; a['>']['^'] = 3; a['>']['>'] = 0; b['v']['v'] = 0; b['v']['<'] = 3; b['v']['^'] = 2; b['v']['>'] = 1; b['<']['v'] = 1; b['<']['<'] = 0; b['<']['^'] = 3; b['<']['>'] = 2; b['^']['v'] = 2; b['^']['<'] = 1; b['^']['^'] = 0; b['^']['>'] = 3; b['>']['v'] = 3; b['>']['<'] = 2; b['>']['^'] = 1; b['>']['>'] = 0; scanf("%s", stra); scanf("%s", strb); scanf("%d", &n); int ansa = 0; if (n % 4 == a[stra[0]][strb[0]]) { ansa += 1; } if (n % 4 == b[stra[0]][strb[0]]) { ansa += 2; } if (ansa == 1) { puts("cw"); } else if (ansa == 2) { puts("ccw"); } else { puts("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 ^ &gt; 1 Output cw Input &lt; ^ 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.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author P Marecki */ 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 in, PrintWriter out) { String s = "v<^>"; int st = s.indexOf(in.nextChar()); int en = s.indexOf(in.nextChar()); int n = in.nextInt(); int cw = (st + n) % 4; int ccw = (st - n + 1_000_000_000) % 4; if (cw == ccw) { out.println("undefined"); } else { out.println(en == cw ? "cw" : "ccw"); } } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public char nextChar() { return next().charAt(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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; char car[] = {'v', '<', '^', '>'}; bool checa(int ini, int fin, int pasos) { pasos %= 4; int aux = 4 + pasos; aux %= 4; ini = (ini + aux) % 4; return (ini == fin); } int num(char c) { int ret = 0; for (int i = 0; i < 4; i++) { if (car[i] == c) { return i; } } return -1; } int main() { char ini, fin; cin >> ini >> fin; int n; cin >> n; bool v1 = checa(num(ini), num(fin), n); bool v2 = checa(num(ini), num(fin), -n); if (v1 && v2) { cout << "undefined\n"; } else if (v1) { cout << "cw\n"; } else if (v2) { 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
# Problem prepared for TheCodingConversations google meet session # to be held on 2020-09-06. If you are a participant in this session # kindly refrain from reading the following solution for your own # benefit. # # author - atifcppprogrammer # 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()) # Moving in round-robin manner in both clock-wise and # counter-clockwise directions to see if spinner stops # at given ending position. isCCW = rotations['ccw'][start][ seconds % 4 ] == end isCW = rotations['cw'][start][ seconds % 4 ] == end # Printing 'ccw or 'cw' if one of the two rotations is # possible, printing 'undefined' if both or neither is # possible. 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
def main(): start, end = input().split() n = int(input()) d = {"v":1, "<":2, "^":3, ">":0} start, end = d[start], d[end] rev = (start - n) % 4 forw = (start + n) % 4 if rev == forw == end: print("undefined") elif rev == end: print("ccw") elif forw == end: print("cw") if __name__ == "__main__": 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 ^ &gt; 1 Output cw Input &lt; ^ 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) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Task solver = new Task(); solver.solve(in, out); out.close(); } } class Task { void solve(InputReader in, PrintWriter out) { String starting = in.nextString(), ending = in.nextString(); int n = in.nextInt(); if (n % 4 == 0 || n % 4 == 2) { out.println("undefined"); } else if (n % 4 == 1 && getNextCw(starting).equals(ending)) { out.println("cw"); } else if (n % 4 == 1 && getNextCcw(starting).equals(ending)) { out.println("ccw"); } else if (n % 4 == 3 && getPreviousCw(starting).equals(ending)) { out.println("cw"); } else if (n % 4 == 3 && getPreviousCcw(starting).equals(ending)) { out.println("ccw"); } else { out.println("undefined"); } } String getNextCw(String position) { switch (position) { case "^": return ">"; case ">": return "v"; case "v": return "<"; case "<": return "^"; default: return null; } } String getPreviousCw(String position) { switch (position) { case "^": return "<"; case ">": return "^"; case "v": return ">"; case "<": return "v"; default: return null; } } String getNextCcw(String position) { switch (position) { case "^": return "<"; case "<": return "v"; case "v": return ">"; case ">": return "^"; default: return null; } } String getPreviousCcw(String position) { switch (position) { case "^": return ">"; case ">": return "v"; case "v": return "<"; case "<": return "^"; default: return null; } } } @SuppressWarnings("WeakerAccess") class InputReader { private BufferedReader reader; private StringTokenizer tokenizer; InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } String next() { String line = null; try { line = reader.readLine(); } catch (IOException e) { e.printStackTrace(); } return line; } String nextString() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } int nextInt() { return Integer.parseInt(nextString()); } long nextLong() { return Long.parseLong(nextString()); } double nextDouble() { return Double.parseDouble(nextString()); } }
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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
''' sunday 30th july'17 codeforces problemA ''' a = [x for x in input().split()] start = a[0] end = a[1] t = int(input()) cw = '^>v<' ccw = '^<v>' if (t + cw.index(start)) % 4 == cw.index(end) and (t + ccw.index(start)) % 4 == ccw.index(end): print("undefined") elif (t + cw.index(start)) % 4 == cw.index(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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
from sys import stdin, stdout arr = ['v','<','^','>'] string = [c for c in stdin.readline().strip().split()] s = string[0] e = string[1] n = int(stdin.readline().strip()) pos = 0 for i in range(4): if s == arr[i]: pos = i break clock = (pos + n) % 4 anti = (pos - n) % 4 if e == arr[clock] and e != arr[anti]: stdout.write("cw") elif e == arr[anti] and e != arr[clock]: stdout.write("ccw") else: stdout.write("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 ^ &gt; 1 Output cw Input &lt; ^ 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.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; 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 { public void solve(int testNumber, InputReader in, PrintWriter out) { char start = in.next().charAt(0); char end = in.next().charAt(0); int N = in.nextInt(); String order = "^>v<"; if (N % 2 == 0) { out.println("undefined"); } else { int si = order.indexOf(start); int ei = order.indexOf(end); if ((si + 1) % 4 == ei) { if (N % 4 == 3) { out.println("ccw"); } else { out.println("cw"); } } else { if (N % 4 == 3) { out.println("cw"); } else { out.println("ccw"); } } } } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
def helper(): s, e = raw_input().split() n = int(raw_input()) char_map = {} r_char_map = {} char_map['^'] = 0 char_map['>'] = 1 char_map['v'] = 2 char_map['<'] = 3 r_char_map['^'] = 0 r_char_map['<'] = 1 r_char_map['v'] = 2 r_char_map['>'] = 3 s_int = char_map[s] e_int = char_map[e] r_s_int = r_char_map[s] r_e_int = r_char_map[e] n %= 4 cw = (n + s_int) %4 ccw = (n + r_s_int) %4 if cw == e_int and ccw != r_e_int: print 'cw' elif ccw == r_e_int and cw != e_int: print 'ccw' else: print 'undefined' helper()
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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.io.*; //PrintWriter import java.math.*; //BigInteger, BigDecimal import java.util.*; //StringTokenizer, ArrayList public class R426_Div2_A { FastReader in; PrintWriter out; public static void main(String[] args) { new R426_Div2_A().run(); } void run() { in = new FastReader(System.in); out = new PrintWriter(System.out); solve(); out.close(); } void solve() { String s1 = in.next(); String s2 = in.next(); int n = in.nextInt(); if (n % 2 == 0) out.println("undefined"); else { String cw = "v<^>"; int i1 = cw.indexOf(s1); int i2 = cw.indexOf(s2); n = n % 4; if ((i1 + n) % 4 == i2) out.println("cw"); else out.println("ccw"); } } //----------------------------------------------------- void runWithFiles() { in = new FastReader(new File("input.txt")); try { out = new PrintWriter(new File("output.txt")); } catch (FileNotFoundException e) { e.printStackTrace(); } solve(); out.close(); } class FastReader { BufferedReader br; StringTokenizer tokenizer; public FastReader(InputStream stream) { br = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public FastReader(File f) { try { br = new BufferedReader(new FileReader(f)); tokenizer = null; } catch (FileNotFoundException e) { e.printStackTrace(); } } private String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) try { tokenizer = new StringTokenizer(br.readLine()); } catch (IOException e) { throw new RuntimeException(e); } return tokenizer.nextToken(); } public String nextLine() { try { return br.readLine(); } catch(Exception e) { throw(new RuntimeException()); } } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } BigInteger nextBigInteger() { return new BigInteger(next()); } BigDecimal nextBigDecimal() { return new BigDecimal(next()); } } }
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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); ; char a, b; long long int n; cin >> a >> b >> n; int z = n % 4; if (n % 2 == 0) { cout << "undefined" << '\n'; exit(0); } int g[119] = {0}; g['^'] = 0; g['>'] = 1; g['v'] = 2; g['<'] = 3; a = g[a]; b = g[b]; if ((b - a + 4) % 4 == z) { cout << "cw" << '\n'; } else cout << "ccw" << '\n'; }
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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import math as mt import sys,string input=sys.stdin.readline import random from collections import deque,defaultdict L=lambda : list(map(int,input().split())) Ls=lambda : list(input().split()) M=lambda : map(int,input().split()) I=lambda :int(input()) s=input().split() n=I() flag=0 if(s[0]=="^" and s[1]==">"): if(n%4==1): ans1="cw" if(n%4==3): ans1="ccw" if(s[0]=="^" and s[1]=="<"): if(n%4==1): ans1="ccw" elif(n%4==3): ans1="cw" if(s[0]=="v" and s[1]==">"): if(n%4==1): ans1="ccw" if(n%4==3): ans1="cw" if(s[0]=="v" and s[1]=="<"): if(n%4==1): ans1="cw" elif(n%4==3): ans1="ccw" if(s[0]=="<" and s[1]=="v"): if(n%4==1): ans1="ccw" if(n%4==3): ans1="cw" if(s[0]=="<" and s[1]=="^"): if(n%4==1): ans1="cw" elif(n%4==3): ans1="ccw" if(s[0]==">" and s[1]=="v"): if(n%4==1): ans1="cw" if(n%4==3): ans1="ccw" if(s[0]==">" and s[1]=="^"): if(n%4==1): ans1="ccw" elif(n%4==3): ans1="cw" if(s[0]=="^" and s[1]=="^"): if(n%4==0): flag=1 if(s[0]=="^" and s[1]=="v"): if(n%4==2): flag=1 if(s[0]=="<" and s[1]=="<"): if(n%4==0): flag=1 if(s[0]=="<" and s[1]==">"): if(n%4==2): flag=1 if(s[0]==">" and s[1]==">"): if(n%4==0): flag=1 if(s[0]==">" and s[1]=="<"): if(n%4==2): flag=1 if(s[0]=="v" and s[1]=="v"): if(n%4==0): flag=1 if(s[0]=="v" and s[1]=="^"): if(n%4==2): flag=1 if(flag==1): print("undefined") else: print(ans1)
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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int cw[1000]; int main() { cw[(int)'v'] = 0; cw[(int)'<'] = 1; cw[(int)'^'] = 2; cw[(int)'>'] = 3; char a, b; cin >> a >> b; int n; cin >> n; int aa = cw[a]; int bb = cw[b]; if (aa == bb || (aa + 2) % 4 == bb) { cout << "undefined"; } else if ((aa + n) % 4 == bb) { cout << "cw"; } else { cout << "ccw"; } return 0; 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.*; public class Main { public static void main(String[] args) { InputReader in = new InputReader(); PrintWriter out = new PrintWriter(System.out); final long start = System.currentTimeMillis(); new Task1().solve(in, out); @SuppressWarnings("unused") final long duration = System.currentTimeMillis()-start; out.close(); } static class Task1{ int diff1, diff2; public void solve(InputReader in, PrintWriter out){ // up right bottom left char start = in.next().charAt(0); char end = in.next().charAt(0); diff(start, end); //out.println(diff1+" "+diff2); int duration = in.nextInt()%4; if(diff1==duration && diff2==duration){ out.println("undefined"); } else if(diff1==duration){ out.println("cw"); } else if(diff2==duration){ out.println("ccw"); } } void diff(char start, char end){ int st=0, e=0; switch(start){ case '^': st = 0; break; case '>': st = 1; break; case 'v': st = 2; break; case '<': st = 3; break; } switch(end){ case '^': e = 0; break; case '>': e = 1; break; case 'v': e=2; break; case '<': e=3; break; } if(e>st){ diff1 = e-st; //clockwise diff2 = 4-e+st; //anti } else if(e<st) { diff1 = 4+e-st; //clockwise diff2 = st-e; //anti } else { diff1 = diff2 = 0; } } long expo(long a, long b, long MOD){ long result = 1; while (b>0){ if (b%2==1) result=(result*a) ; b>>=1; a=(a*a) ; } return result ; } long inverseModullo(long numerator, long denominator, long MOD){ return ((numerator )*(expo(denominator, MOD-2, MOD))) ; } } static class InputReader{ final InputStream stream; final byte[] buf = new byte[8192]; int curChar, numChars; SpaceCharFilter filter; public InputReader(){ this.stream = System.in; } 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 long nextLong(){ int c = read(); while(isSpaceChar(c)) c = read(); int sgn = 1; if(c == '-'){ sgn = -1; c = read(); } long 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 next(){ 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 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 ^ &gt; 1 Output cw Input &lt; ^ 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.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.OptionalInt; import java.util.Set; import java.util.Stack; import java.util.StringTokenizer; import java.util.TreeSet; import java.util.stream.Collectors; public class Solution implements Runnable { private void solve() throws IOException { //max_int > 2 * 10^9 String s = nextToken(); String e = nextToken(); int n = nextInt(); if (n % 2 == 0) { writer.print("undefined"); } else { int x = n % 4; if (x == 1) { if (s.equals("^")) { if (e.equals(">")) { writer.print("cw"); } else { writer.print("ccw"); } } else if (s.equals(">")) { if (e.equals("v")) { writer.print("cw"); } else { writer.print("ccw"); } } else if (s.equals("v")) { if (e.equals("<")) { writer.print("cw"); } else { writer.print("ccw"); } } else if (s.equals("<")) { if (e.equals("^")) { writer.print("cw"); } else { writer.print("ccw"); } } } else if (x == 3) { if (s.equals("^")) { if (e.equals("<")) { writer.print("cw"); } else { writer.print("ccw"); } } else if (s.equals(">")) { if (e.equals("^")) { writer.print("cw"); } else { writer.print("ccw"); } } else if (s.equals("v")) { if (e.equals(">")) { writer.print("cw"); } else { writer.print("ccw"); } } else if (s.equals("<")) { if (e.equals("v")) { writer.print("cw"); } else { writer.print("ccw"); } } } } } private List<Integer> primeFact(int n) { List<Integer> factors = new ArrayList<Integer>(); for (int i = 2; i <= n / i; i++) { while (n % i == 0) { factors.add(i); n /= i; } } if (n > 1) factors.add(n); return factors.stream().distinct().collect(Collectors.toList()); } private List<Integer> findPrimes(int n) { boolean prime[] = new boolean[n+1]; for(int i=0;i<n;i++) prime[i] = true; for(int p = 2; p*p <=n; p++) { if(prime[p] == true) { for(int i = p*2; i <= n; i += p) prime[i] = false; } } List<Integer> list = new ArrayList<Integer>(); for(int i = 2; i <= n; i++) { if(prime[i] == true) list.add(i); } return list; } private List<Long> fact(long n) { TreeSet<Long> factors = new TreeSet<Long>(); factors.add(n); factors.add(1L); for(long i = n - 1; i >= Math.sqrt(n); i--) if(n % i == 0) { factors.add(i); factors.add(n / i); } return factors.stream().collect(Collectors.toList()); } private String minFact(long n) { String str = 1 + " " + n; long min = Long.MAX_VALUE; for(long i = n - 1; i >= Math.sqrt(n); i--) if(n % i == 0) { long x = i - n/i; if (x < min) { min = x; str = n/i + " " + i; } } return str; } private long gcd (long a, long b) { BigInteger b1 = BigInteger.valueOf(a); BigInteger b2 = BigInteger.valueOf(b); return b1.gcd(b2).longValue(); } private long lcm (long a, long b, long gcd) { return a * b / gcd; } private boolean isPowerOfTwo(long x) { return (x != 0) && ((x & (x - 1)) == 0); } private int exponentOfTwo(long n) { return (int)( Math.floor(Math.log(n) / Math.log(2))); } private Long sumDiagLR (Long[][] array) { long sum = 0; int i = 0, j = 0; while (i < array.length && j < array.length) { sum += array[i][j]; i++; j++; } return sum; } private Long sumDiagRL (Long[][] array) { long sum = 0; int i = array.length-1, j = 0; while (i >=0 && j < array.length) { sum += array[i][j]; i--; j++; } return sum; } private BigInteger factorial( String n ) { BigInteger k = new BigInteger( n ); BigInteger ans = BigInteger.ONE; while ( k.compareTo( BigInteger.ONE ) > 0 ) { ans = ans.multiply( k ); k = k.subtract( BigInteger.ONE ); } return ans; } private long combinations( long n, long r ) { return ( factorial( String.valueOf( n ) ).divide( ( new BigInteger( String.valueOf( r ) ).multiply( factorial( String.valueOf( n - r ) ) ) ) ) ).longValue(); } private String binaryXOR( String s1, String s2 ) { BigInteger a = new BigInteger( s1, 2 ); BigInteger b = new BigInteger( s2, 2 ); return a.xor( b ).toString( 2 ); } private static void findDP( Node node ) { for ( Node child : node.children ) { if ( child.value > node.value ) { child.dp = Math.max( child.dp, node.dp + 1 ); //findDP( child ); } } } private static class Obj implements Comparable<Obj> { String name; int value; public Obj( int value ) { this.value = value; } public Obj( String name, int value ) { this.name = name; this.value = value; } @Override public int compareTo( Obj o ) { return o.value - this.value; } } private static class Edge { PNode src; PNode des; long cost; public Edge (PNode src, PNode des, long cost) { this.src = src; this.des = des; this.cost = cost; } } private static class PNode { List<Edge> edges; long value; boolean isTrue; public PNode() { this.edges = new ArrayList<>( ); this.isTrue = false; } public PNode(long value ) { this.edges = new ArrayList<>( ); this.isTrue = false; this.value = value; } } private static class Node { long value; long dp; List<Node> children; Node parent; public Node(){}; public Node( int value ) { this.value = value; dp = 1; children = new ArrayList<Node>(); } } private static boolean isInt( String s ) { if ( s.length() < 1 ) return false; else { for ( char c : s.toCharArray() ) { if ( c < '0' || c > '9' ) { return false; } } } return true; } private static Map<String, Integer> findSubString( String s, int k ) { Map<String, Integer> map = new HashMap<>(); for ( int i = 0; i < s.length() - ( k - 1 ); i++ ) { String str = new String( s.substring( i, i + k ) ); if ( map.containsKey( str ) ) { map.put( str, map.get( str ) + 1 ); } else { map.put( str, 1 ); } } return map; } //mergesort public static Comparable[] mergeSort( Comparable[] list ) { if ( list.length <= 1 ) { return list; } Comparable[] left = new Comparable[ list.length / 2 ]; Comparable[] right = new Comparable[ list.length - left.length ]; System.arraycopy( list, 0, left, 0, left.length ); System.arraycopy( list, left.length, right, 0, right.length ); mergeSort( left ); mergeSort( right ); merge( left, right, list ); return list; } private static void merge( Comparable[] left, Comparable[] right, Comparable[] result ) { int leftIdx = 0; int rightIdx = 0; int index = 0; while ( leftIdx < left.length && rightIdx < right.length ) { if ( left[ leftIdx ].compareTo( right[ rightIdx ] ) < 0 ) { result[ index++ ] = left[ leftIdx ]; leftIdx++; } else { result[ index++ ] = right[ rightIdx ]; rightIdx++; } } System.arraycopy( left, leftIdx, result, index, left.length - leftIdx ); System.arraycopy( right, rightIdx, result, index, right.length - rightIdx ); } public static List<Obj> mergeSort( List<Obj> list ) { if ( list.size() <= 1 ) { return list; } List<Obj> left = new ArrayList( list.subList( 0, list.size() / 2 ) ); List<Obj> right = new ArrayList( list.subList( left.size(), list.size() ) ); left = mergeSort( left ); right = mergeSort( right ); list = merge( left, right ); return list; } private static List<Obj> merge( List<Obj> left, List<Obj> right ) { int leftCounter = 0, rightCounter = 0; List<Obj> result = new ArrayList<>(); while ( leftCounter < left.size() && rightCounter < right.size() ) { Obj leftItem = left.get( leftCounter ); Obj rightItem = right.get( rightCounter ); if ( leftItem.compareTo( rightItem ) < 0 ) { result.add( leftItem ); leftCounter++; } else { result.add( rightItem ); rightCounter++; } } if ( leftCounter >= left.size() ) result.addAll( right.subList( rightCounter, right.size() ) ); else if ( rightCounter >= right.size() ) result.addAll( left.subList( leftCounter, left.size() ) ); return result; } public static void main( String[] args ) { new Solution().run(); } BufferedReader reader; StringTokenizer tokenizer; PrintWriter writer; public void run() { try { reader = new BufferedReader( new InputStreamReader( System.in ) ); tokenizer = null; writer = new PrintWriter( System.out ); solve(); reader.close(); writer.close(); } catch ( Exception e ) { e.printStackTrace(); System.exit( 1 ); } } int nextInt() throws IOException { return Integer.parseInt( nextToken() ); } long nextLong() throws IOException { return Long.parseLong( nextToken() ); } double nextDouble() throws IOException { return Double.parseDouble( nextToken() ); } String nextToken() throws IOException { while ( tokenizer == null || !tokenizer.hasMoreTokens() ) { tokenizer = new StringTokenizer( reader.readLine() ); } return tokenizer.nextToken(); } public class Tuple { Object fst; Object snd; public Tuple(Object fst, Object snd) { this.fst = fst; this.snd = snd; } public Object getFst() { return fst; } public Object getSnd() { return snd; } } // Arrays.sort(array, Comparator.comparing((int[] arr) -> arr[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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int main() { map<char, int> mp; mp['^'] = 1; mp['>'] = 2; mp['v'] = 3; mp['<'] = 4; char st, en; cin >> st >> en; int n; cin >> n; int rotateCountForCW = (mp[en] - mp[st] + 4) % 4; int rotateCountForCCW = (mp[st] - mp[en] + 4) % 4; if (rotateCountForCW == rotateCountForCCW) cout << "undefined\n"; else if (rotateCountForCW == n % 4) 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
spinner=['v','<','^','>'] reverse=['v','>','^','<'] x=raw_input() a,b=x[0],x[-1] n=input() i=spinner.index(a) final=(i+n)%4 m=reverse.index(a) fin=(m+n)%4 if spinner[final]==b and reverse[fin]!=b: print 'cw' elif reverse[fin]==b and spinner[final]!=b: print 'ccw' elif spinner[final]==b and reverse[fin]==b: 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int main(void) { ios ::sync_with_stdio(0); cin.tie(0); string cw = "^>v<", ccw = "^<v>"; char start, end; int n, i, j; cin >> start >> end >> n; i = (cw.find(start) + (n % 4)) % 4; j = (ccw.find(start) + (n % 4)) % 4; if (cw[i] == ccw[j]) { cout << "undefined" << endl; } else { if (cw[i] == end) { 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; char s1[10], s2[10]; long long n; long long get_p(char x) { if (x == 'v') return 0; else if (x == '<') return 1; else if (x == '^') return 2; else return 3; } int main() { scanf("%s%s%lld", s1, s2, &n); n %= 4; long long p1 = get_p(s1[0]), p2 = get_p(s2[0]); long long flag = 0; if ((p1 + n) % 4 == p2) ++flag; if ((p1 - n + 4) % 4 == p2) ++flag; if (flag == 2) puts("undefined"); else { if ((p1 + n) % 4 == p2) puts("cw"); else if ((p1 - n + 4) % 4 == p2) puts("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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int main() { char c1, c2; int n; cin >> c1 >> c2; cin >> n; if (n == 0) { cout << "undefined"; return 0; } int as1 = int(c1); int as2 = int(c2); int in1, in2; if (as1 == 118) in1 = 0; else if (as1 == 60) in1 = 1; else if (as1 == 94) in1 = 2; else in1 = 3; if (as2 == 118) in2 = 0; else if (as2 == 60) in2 = 1; else if (as2 == 94) in2 = 2; else in2 = 3; int f1 = (in1 + n) % 4; int comp1 = in2; if (as1 == 118) in1 = 0; else if (as1 == 62) in1 = 1; else if (as1 == 94) in1 = 2; else in1 = 3; if (as2 == 118) in2 = 0; else if (as2 == 62) in2 = 1; else if (as2 == 94) in2 = 2; else in2 = 3; int f2 = (in1 + n) % 4; int comp2 = in2; if (f1 == comp1 && f2 == comp2) cout << "undefined"; else if (f1 == comp1) cout << "cw"; else 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
a, b = (i for i in input().split()) n = int(input())%4 if n%2: if a == 'v': if b == '>' and n == 1 or b == '<' and n == 3: print('ccw') else: print('cw') elif a== '>': if b == '^' and n == 1 or b == 'v' and n == 3: print('ccw') else: print('cw') elif a== '^': if b == '<' and n == 1 or b == '>' and n == 3: print('ccw') else: print('cw') elif a== '<': if b == 'v' and n == 1 or b == '^' and n == 3: print('ccw') else: 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
s,t = input().split() n = int(input()) a = '^>v<' if n%2==0: print('undefined') else: i = a.find(s) d = a.find(t) if a[(i+n)%4]==t: 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> int sign(char ch) { switch (ch) { case 'v': return 0; case '<': return 1; case '^': return 2; case '>': return 3; } } int main(void) { int s, g, n; char ch = getchar(); s = sign(ch); getchar(); ch = getchar(); g = sign(ch); int step = (g - s + 4) % 4; scanf("%d", &n); n %= 4; bool cw = step == n; bool ccw = (step + n) % 4 == 0; if (cw && !ccw) printf("cw\n"); else if (!cw && ccw) 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.io.*; import java.util.*; public class Solution { static StringBuilder fin = new StringBuilder(""); public static void main(String[] args) { Scanner in = new Scanner(System.in); char s = in.next().charAt(0); char t = in.next().charAt(0); char a[] = {'^','>','v','<'}; char b[] = {'^','<','v','>'}; int inda = 0,indb=0; for(int i=0;i<4;i++) { if(a[i] == s ) inda=i; if(b[i] == s) indb=i; } int n = in.nextInt(); n=n%4; char aa = a[ (inda + n)%4]; char bb = b[(indb + n)%4]; if(aa == t && bb==t) System.out.println("undefined"); else if(aa==t) 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
if __name__ == "__main__": x, y = input().split() n = int(input()) dirs = {'^': 1, '>': 2, 'v': 3, '<': 4} if n%2 == 0: print('undefined') elif (dirs[y]-dirs[x])%4 == n%4: 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.io.BufferedReader; import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class TheUselessToy implements Closeable { private InputReader in = new InputReader(System.in); private PrintWriter out = new PrintWriter(System.out); public void solve() { char start = in.next().charAt(0), end = in.next().charAt(0); int n = in.ni() % 4; char x = start, y = start; for (int i = 0; i < n; i++) { x = rotateClockWise(x); y = rotateCounterClockWise(y); } if (x == end && y == end) { out.println("undefined"); } else if (x == end) { out.println("cw"); } else { out.println("ccw"); } } private char rotateClockWise(char c) { if (c == '^') return '>'; if (c == '>') return 'v'; if (c == 'v') return '<'; if (c == '<') return '^'; return 0x0000; } private char rotateCounterClockWise(char c) { if (c == '^') return '<'; if (c == '>') return '^'; if (c == 'v') return '>'; if (c == '<') return 'v'; return 0x0000; } @Override public void close() throws IOException { in.close(); out.close(); } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int ni() { return Integer.parseInt(next()); } public long nl() { return Long.parseLong(next()); } public void close() throws IOException { reader.close(); } } public static void main(String[] args) throws IOException { try (TheUselessToy instance = new TheUselessToy()) { instance.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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; long long state(char c) { if (c == 'v') return 0; else if (c == '<') return 1; else if (c == '^') return 2; else return 3; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); char a, b; cin >> a >> b; long long c = state(a), f = state(b); long long n; cin >> n; n %= 4; if ((c + n) % 4 == f) { if ((c - n + 4) % 4 == f) cout << "undefined"; else cout << "cw"; } else if ((c - n + 4) % 4 == f) 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.io.*; import java.util.*; import java.lang.*; import static java.lang.System.*; public class A { public static void main (String args[]) throws Exception { Scanner sc=new Scanner(in); String s=sc.nextLine(); int n=sc.nextInt(); char arr[]={'v','<','^','>'}; char brr[]={'v','>','^','<'}; char a=s.charAt(0); char b=s.charAt(2); int start=0,stop=0; n=n%4; int flag1=0; int flag2=0; for(int i=0;i<4;i++) { if(arr[i]==a) start=i; if(arr[i]==b) stop=i; } int diff=0; if(start<=stop) diff=stop-start; else { diff=4-start+stop; } if(diff==n) { flag1=1; } for(int i=0;i<4;i++) { if(brr[i]==a) start=i; if(brr[i]==b) stop=i; } diff=0; if(start<=stop) diff=stop-start; else { diff=4-start+stop; } if(diff==n) { flag2=1; } if(flag1==flag2) out.println("undefined"); else { if(flag1==1) out.println("cw"); else out.println("ccw"); } } } class Number { int a; int b; int c; public Number(int x,int y,int z) { a=x; b=y; c=z; } } class Ch1Comparator implements Comparator<Number> { public int compare(Number f1,Number f2) { if(f1.a==f2.a) return 0; if(f1.a<f2.a) return -1; return 1; } } class Ch2Comparator implements Comparator<Number> { public int compare(Number f1,Number f2) { if(f1.b==f2.b) return 0; if(f1.b<f2.b) return -1; return 1; } }class Ch3Comparator implements Comparator<Number> { public int compare(Number f1,Number f2) { if(f1.c==f2.c) return 0; if(f1.c<f2.c) return -1; return 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
dir = raw_input().split() n = int(raw_input()) n = n%4 if n==0 or n==2: print "undefined" elif n==1: if dir == ['^','>'] or dir == ['>','v'] or dir == ['v','<'] or dir == ['<','^']: print "cw" else: print "ccw" else: if dir == ['^','>'] or dir == ['>','v'] or dir == ['v','<'] or dir == ['<','^']: 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>; template <typename T> inline T gcd(T a, T b) { T c; while (b) { c = b; b = a % b; a = c; } return a; } const double PI = acos(-1); const long long MOD = 1000000007; const int INF = 0x3f3f3f3f; const long long LLINF = 0x3f3f3f3f3f3f3f3f; char cw[] = {94, 62, 118, 60, 94, 62, 118, 60, 94, 62, 118}; char ccw[] = {94, 60, 118, 62, 94, 60, 118, 62, 94, 60, 118}; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed << setprecision(12); char s, e; int n; cin >> s >> e; cin >> n; n %= 4; int idx = 0; for (int i = 0; i < 11; i++) { if (cw[i] == s) { idx = i; break; } } int a = -1; int b = -1; if (cw[idx + n] == e) { a = 0; } idx = 0; for (int i = 0; i < 11; i++) { if (ccw[i] == s) { idx = i; break; } } if (ccw[idx + n] == e) { b = 0; } if (a == 0 && b == 0) { cout << "undefined" << "\n"; } else if (a == 0) { cout << "cw" << "\n"; } else if (b == 0) 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
def cw(c, n): if c == '^': if n == 1: return '>' if n == 3: return '<' if c == '>': if n == 1: return 'v' if n == 3: return '^' if c == 'v': if n == 1: return '<' if n == 3: return '>' if c == '<': if n == 1: return '^' if n == 3: return 'v' def rev(c): if c == 'v': return '^' if c == '^': return 'v' if c == '<': return '>' return '<' st, f = input().split() n = int(input()) if f == rev(st) or f == st: print('undefined') elif f == cw(st, n % 4): 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int main() { char a, b; int n, i1, i2; cin >> a >> b >> n; char u[] = {'v', '<', '^', '>'}; char u2[] = {'v', '>', '^', '<'}; for (int i = 0; i < 4; i++) { if (u[i] == a) i1 = i + 1; if (u2[i] == a) i2 = i + 1; } i1 = (i1 + n) % 4; if (i1 == 0) i1 = 4; i2 = (i2 + n) % 4; if (i2 == 0) i2 = 4; i1--; i2--; if (u[i1] == b && u2[i2] == b) cout << "undefined"; else if (u[i1] == b) cout << "cw"; else if (u2[i2] == b) 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
i, f = map(str, input().split(' ')) n = int(input()) cw = ["^",">","v","<"] ccw = ["^","<","v",">"] inicio = cw.index(i) _cw = (cw[(inicio+(n%4))%4]) inicio1 = ccw.index(i) _ccw = (ccw[(inicio1+(n%4))%4]) if _cw == f and _ccw != f: print("cw") elif _ccw == f and _cw != f: print("ccw") elif _cw == f and _ccw == f: 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
cw = ['v', '<', '^', '>'] ccw = ['v', '>', '^', '<'] cw_map = {} for idx, sign in enumerate(cw): cw_map[sign] = idx ccw_map = {} for idx, sign in enumerate(ccw): ccw_map[sign] = idx # print ccw_map a, b = raw_input().split() turns = input() # If clockwise position final = cw[(cw_map[a] + turns) % 4] ans = None count = 0 if final == b: ans = 'cw' count = count + 1 final = ccw[(ccw_map[a] + turns) % 4] if final == b: ans = 'ccw' count = count + 1 if count == 0 or count == 2: print 'undefined' else: 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; char a[] = {'^', '>', 'v', '<', '^', '>', 'v', '<', '^', '>', 'v', '<'}; int main() { char pre, now; int n, t; scanf("%c %c", &pre, &now); scanf("%d", &n); for (int i = 0; i < 4; ++i) if (a[i] == pre) t = i; n %= 4; t += 4; if (a[t - n] == now && a[t + n] == now) printf("undefined"); else if (a[t - n] == now) printf("ccw"); else if (a[t + n] == now) printf("cw"); else printf("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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { boolean cwFlag, ccwFlag; char[] cw = {'^', '>', 'v', '<'}; char[] ccw = {'^', '<', 'v', '>'}; public static void main(String[] args) throws IOException { new Main().run(); } public void run() throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] spin = br.readLine().split(" "); char start = spin[0].charAt(0); char end = spin[1].charAt(0); long n = Integer.parseInt(br.readLine()); char curr = start; int currCount = 0; int mod = (int)(n % 4); if(curr == end && n == 0) { cwFlag = true; } else { for (int i = 0; i < mod; i++) { if (curr == '^') { curr = '>'; } else if (curr == '>') { curr = 'v'; } else if (curr == 'v') { curr = '<'; } else if (curr == '<') { curr = '^'; } currCount++; if (curr == end && currCount == mod) { cwFlag = true; break; } } } curr = start; currCount = 0; if(curr == end && n == 0) { ccwFlag = true; } else { for (int i = 0; i < mod; i++) { if (curr == '^') { curr = '<'; } else if (curr == '<') { curr = 'v'; } else if (curr == 'v') { curr = '>'; } else if (curr == '>') { curr = '^'; } currCount++; if (curr == end && currCount == mod) { ccwFlag = true; break; } } } if(cwFlag && !ccwFlag) { System.out.println("cw"); } else if(!cwFlag && ccwFlag) { 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
hs = {} hs['^'] = 0 hs['>'] = 1 hs['v'] = 2 hs['<'] = 3 x,y = map(lambda x : hs[x],raw_input().split()) n = input() n%=4 cw = (x+n)%4 ccw = ((x-n)+4)%4 if(cw==y and ccw == y): print "undefined" elif(cw == y): 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 ^ &gt; 1 Output cw Input &lt; ^ 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.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; 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; FastReader in = new FastReader(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, FastReader in, PrintWriter out) { char s = in.next().charAt(0); char e = in.next().charAt(0); int n = in.nextInt(); n %= 4; if (n == 0 || n == 2) { out.print("undefined"); return; } for (int i = 0; i < n; i++) { switch (s) { case '^': s = '>'; break; case '>': s = 'v'; break; case 'v': s = '<'; break; case '<': s = '^'; break; } } out.print(s == e ? "cw" : "ccw"); } } static class FastReader { private final BufferedReader reader; private StringTokenizer token; public FastReader(InputStream in) { reader = new BufferedReader(new InputStreamReader(in)); } String next() { while (token == null || !token.hasMoreElements()) { try { token = new StringTokenizer(reader.readLine()); } catch (IOException e) { e.printStackTrace(); } } return token.nextToken(); } int nextInt() { return Integer.parseInt(next()); } } }
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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import sys a = sys.stdin.readline() a = a.strip() a = a.split(' ') b = sys.stdin.readline() remain = int(b) % 4 pos = ['v', '<', '^', '>'] startPos = 5 for i,position in enumerate(pos): if a[0] == position: startPos = i if remain != 2 and remain != 0: if startPos + remain < len(pos): if a[1] == pos[startPos + remain]: sys.stdout.write("cw") elif a[1] == pos[startPos - remain]: sys.stdout.write("ccw") elif startPos + remain >= len(pos): if a[1] == pos[(startPos + remain) - 4]: sys.stdout.write("cw") elif a[1] == pos[startPos - remain]: sys.stdout.write("ccw") else: sys.stdout.write("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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.util.Scanner; public class Main{ private static int getIndex(char ch) { if (ch == '^') { return 0; } else if (ch == '>') { return 1; } else if (ch == 'v') { return 2; } else { return 3; } } public static void main(String[] args) { Scanner scan = new Scanner(System.in); char ch1 , ch2; ch1 = scan.next().charAt(0); ch2 = scan.next().charAt(0); int n = scan.nextInt(); int index1 = getIndex(ch1) , index2 = getIndex(ch2); int diff1 = index2 - index1; if (diff1 < 0) { diff1 = (4 - Math.abs(index1 - index2)) % 4; } int diff2 = (4 - diff1) % 4; if (n % 4 == diff1 && n % 4 != diff2) { System.out.println("cw"); } else if (n % 4 == diff2 && n % 4 != diff1) { 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
sym = list(map(str, input().split())) n = int(input()) if n%2 == 0: print("undefined") else: dict = {'<':0, '^': 1, '>': 2, 'v': 3} print("cw") if dict[sym[len(sym)-1]] == (dict[sym[0]] + n)%4 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; int i, j, k, m, n, a, b, c, tc, o, ini, en, cw, ccw; char x[10], y[10]; char p[] = {'>', 'v', '<', '^'}; char pc[] = {'>', '^', '<', 'v'}; int main() { scanf("%s", x); scanf("%s", y); scanf("%d", &n); if (x[0] == p[0]) ini = 0; else if (x[0] == p[1]) ini = 1; else if (x[0] == p[2]) ini = 2; else if (x[0] == p[3]) ini = 3; if (y[0] == p[0]) en = 0; else if (y[0] == p[1]) en = 1; else if (y[0] == p[2]) en = 2; else if (y[0] == p[3]) en = 3; if ((ini + n) % 4 == en) cw = 1; else cw = 0; if (x[0] == pc[0]) ini = 0; else if (x[0] == pc[1]) ini = 1; else if (x[0] == pc[2]) ini = 2; else if (x[0] == pc[3]) ini = 3; if (y[0] == pc[0]) en = 0; else if (y[0] == pc[1]) en = 1; else if (y[0] == pc[2]) en = 2; else if (y[0] == pc[3]) en = 3; if ((ini + n) % 4 == en) ccw = 1; else ccw = 0; if (!(cw ^ ccw)) printf("undefined\n"); else if (cw) printf("cw\n"); else 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
s = raw_input() start = s[0] end = s[2] n = int(raw_input()) if n%2==0: print 'undefined' else: if n%4 == 1: if ((start == '^' and end == '>') or (start == '>' and end == 'v') or (start == 'v' and end == '<') or (start == '<' and end == '^')): print 'cw' else: print 'ccw' elif n%4 == 3: if ((start == '^' and end == '<') or (start == '>' and end == '^') or (start == 'v' and end == '>') or (start == '<' and end == 'v')): 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.util.*; public class test { public static void main(String[] args){ Scanner scanner = new Scanner(System.in); String str = scanner.next(); char ch1 = str.charAt(0); str = scanner.next(); char ch2 = str.charAt(0); int n = scanner.nextInt(); n = n % 4; if (n == 0 || n == 2){ System.out.println("undefined"); return; } if ((ch1 == 'v' && ch2 == '<') || (ch1 == '<' && ch2 == '^') || (ch1 == '^' && ch2 == '>') || (ch1 == '>' && ch2 == 'v')){ if (n == 1){ System.out.println("cw"); return; }else{ System.out.println("ccw"); } }else{ if (n == 1){ System.out.println("ccw"); return; }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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
def main(a, b, n): ccw = ["^", "<", "v", ">"] * 2 cw = ["^", ">", "v", "<"] * 2 if n % 2 == 0: return "undefined" n = n % 4 if b == ccw[(ccw.index(a) + n)]: return "ccw" elif b == cw[(cw.index(a) + n)]: return "cw" return "undefined" print(main(*input().split(' '), int(input())))
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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
a,b=raw_input().split() a='^>v<'.index(a) b='^>v<'.index(b) d=(b-a)&3 e=(4-d)&3 n=input()&3 print 'cw' if d==n and e!=n else 'ccw' if e==n and d!=n else '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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
#include <bits/stdc++.h> using namespace std; int n; char x, y; int cal(char x) { if (x == 'v') return 1; if (x == '<') return 2; if (x == '^') return 3; if (x == '>') return 4; } int main() { scanf("%c %c\n%d", &x, &y, &n); n %= 4; int t = cal(y) - cal(x); if (t < 1) t += 4; if (n == 0 || n == 2) { printf("undefined"); return 0; } if (t == n) printf("cw"); else if (t == 4 - n) printf("ccw"); else printf("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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
s , f = map(ord, input().split(' ')) n = int(input()) a = [118, 60, 94, 62] if not(n % 2): print('undefined') else: n %= 4 k = a.index(s) if a[k-n] == f: print('ccw') else: 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.util.Scanner; public class Mag { public static void main(String[] args) { Scanner scan = new Scanner(System.in); char start = scan.next().charAt(0); char finish = scan.next().charAt(0); int s = scan.nextInt(); if(s % 2 == 0) System.out.println("undefined"); else{ s = s % 4; if(start == 94 && (finish == 62 && s == 1 || finish == 60 && s == 3) || start == 118 && (finish == 60 && s == 1 || finish == 62 && s == 3) || start == 60 &&(finish == 94 && s == 1 || finish == 118 && s == 3) || start == 62 && (finish == 118 && s == 1 || finish == 94 && s == 3)){ 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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
while True: try: a,b=input().split() c=int(input()) c%=4 s=n=0 if a=='>': if c==3: a='^' elif c==1: a='v' elif c==2: a='<' if a==b: s=1 a='>' if c==3: a='v' elif c==1: a='^' elif c==2: a='<' if a==b: n=1 elif a=='v': if c==3: a='>' elif c==1: a='<' elif c==2: a='^' if a==b: s=1 a='v' if c==3: a='<' elif c==1: a='>' elif c==2: a='^' if a==b: n=1 elif a=='<': if c==3: a='v' elif c==1: a='^' elif c==2: a='>' if a==b: s=1 a='<' if c==3: a='^' elif c==1: a='v' elif c==2: a='>' if a==b: n=1 elif a=='^': if c==3: a='<' elif c==1: a='>' elif c==2: a='v' if a==b: s=1 a='^' if c==3: a='>' elif c==1: a='<' elif c==2: a='v' if a==b: n=1 if s==1 and n!=1: print("cw") if s!=1 and n==1: print("ccw") if s==1 and n==1: print("undefined") except EOFError: break
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 ^ &gt; 1 Output cw Input &lt; ^ 3 Output ccw Input ^ v 6 Output undefined
2
7
import java.io.*; import java.util.*; public class A { FScanner in = new FScanner(); PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out), true); void run() { char c1 = in.next().charAt(0); char c2 = in.next().charAt(0); int x = -1, y = -1; if (c1 == '^') x = 1; else if (c1 == '>') x = 2; else if (c1 == 'v') x = 3; else if (c1 == '<') x = 4; if (c2 == '^') y = 1; else if (c2 == '>') y = 2; else if (c2 == 'v') y = 3; else if (c2 == '<') y = 4; int n = in.nextInt(); String ans = ""; if (n % 2 == 0) ans = "undefined"; else if ((x + n) % 4 == y % 4) ans = "cw"; else if ((y + n) % 4 == x % 4) ans = "ccw"; out.print(ans); out.close(); } public static void main(String[] args){ new A().run(); } static class FScanner { BufferedReader br; StringTokenizer st; FScanner() { 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