prompt
string
response
string
Problem: <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 Solution (in PYTHON3):
a,b=map(str,input().split()) n=int(input()) l=[118,60,94,62] for x in range(4): if l[x]==ord(a): c1=x if l[x]==ord(b): c2=x if (c2-c1)%4==0 or (c2-c1)%4==2: p='undefined' elif ((c2-c1)%4==1 and n%4==1) or ((c2-c1)%4==3 and n%4==3): p='cw' else: p='ccw' print(p)
Problem: <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 Solution (in CPP):
#include <bits/stdc++.h> using namespace std; int main() { char s, s1; cin >> s >> s1; long int n; cin >> n; n %= 4; if (n == 0 || n == 2) cout << "undefined" << endl; else if (((s == 'v' && s1 == '<') || (s == '<' && s1 == '^') || (s == '^' && s1 == '>') || (s == '>' && s1 == 'v')) && n == 1) cout << "cw" << endl; else if (((s == 'v' && s1 == '<') || (s == '<' && s1 == '^') || (s == '^' && s1 == '>') || (s == '>' && s1 == 'v')) && n == 3) cout << "ccw" << endl; else if (((s == 'v' && s1 == '>') || (s == '<' && s1 == 'v') || (s == '^' && s1 == '<') || (s == '>' && s1 == '^')) && n == 3) cout << "cw" << endl; else if (((s == 'v' && s1 == '>') || (s == '<' && s1 == 'v') || (s == '^' && s1 == '<') || (s == '>' && s1 == '^')) && n == 1) cout << "ccw" << endl; else cout << "undefined" << endl; return 0; }
Problem: <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 Solution (in CPP):
#include <bits/stdc++.h> using namespace std; int main() { long long n; int r, c1 = 0, c2 = 0; string s1, s2, sb, se; cin >> sb; cin >> se; cin >> n; if (n == 0) { cout << "undefined" << endl; return 0; } if (sb == "v") { s1 = "v<^>"; s2 = "v>^<"; } else if (sb == "<") { s1 = "<^>v"; s2 = "<v>^"; } else if (sb == "^") { s1 = "^>v<"; s2 = "^<v>"; } else if (sb == ">") { s1 = ">v<^"; s2 = ">^<v"; } r = n % 4; if (s1[r] == se[0]) { c1 = 1; } if (s2[r] == se[0]) { c2 = 1; } if ((c1 == 1) && (c2 == 1)) { cout << "undefined" << endl; return 0; } else if (c1 == 1) { cout << "cw" << endl; return 0; } else { cout << "ccw" << endl; return 0; } }
Problem: <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 Solution (in CPP):
#include <bits/stdc++.h> using namespace std; int a[1000]; int main() { char x, y; cin >> x >> y; a['^'] = 0; a['>'] = 1; a['v'] = 2; a['<'] = 3; int z; cin >> z; z %= 4; if (z % 2 == 0) { cout << "undefined"; } else if ((a[x] + z) % 4 == a[y]) { cout << "cw"; } else { cout << "ccw"; } }
Problem: <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 Solution (in PYTHON3):
def cw(d,n): f=['^','>','v','<'] if d==f[0]: if n%4==1: return f[1] elif n%4==2: return f[2] elif n%4==3: return f[3] else: return f[0] elif d==f[1]: if n%4==1: return f[2] elif n%4==2: return f[3] elif n%4==3: return f[0] else: return f[1] elif d==f[2]: if n%4==1: return f[3] elif n%4==2: return f[0] elif n%4==3: return f[1] else: return f[2] elif d==f[3]: if n%4==1: return f[0] elif n%4==2: return f[1] elif n%4==3: return f[2] else: return f[3] def ccw(d,e): f=['^','<','v','>'] if d==f[0]: if n%4==1: return f[1] elif n%4==2: return f[2] elif n%4==3: return f[3] else: return f[0] elif d==f[1]: if n%4==1: return f[2] elif n%4==2: return f[3] elif n%4==3: return f[0] else: return f[1] elif d==f[2]: if n%4==1: return f[3] elif n%4==2: return f[0] elif n%4==3: return f[1] else: return f[2] elif d==f[3]: if n%4==1: return f[0] elif n%4==2: return f[1] elif n%4==3: return f[2] else: return f[3] s=list(map(str,input().split())) n=int(input()) a=cw(s[0],n) b=ccw(s[0],n) if a==b: print("undefined") elif a==s[1]: print('cw') elif b==s[1]: print('ccw') else: print('undefined')
Problem: <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 Solution (in PYTHON3):
a, b = input().split() n = int(input()) mp = {'v': 0, '<': 1, '^': 2, '>': 3} u = (mp[b] - mp[a] + 4) % 4 if(u == 0 or u == 2): print('undefined') elif(u == n % 4): print('cw') else: print('ccw')
Problem: <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 Solution (in PYTHON):
s, e = raw_input().split() n = input() cw = {'^': 0, '>': 1, 'v': 2, '<': 3} ccw = {'^': 0, '<': 1, 'v': 2, '>': 3} n %= 4 p1 = cw[s] p2 = ccw[s] p3 = (p1 + n) % 4 p4 = (p2 + n) % 4 for key, val in cw.iteritems(): if val == p3: key1 = key for key, val in ccw.iteritems(): if val == p4: key2 = key if key2 == key1: print 'undefined' else: if key1 == e: print 'cw' elif key2 == e: print 'ccw' else: print 'undefined'
Problem: <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 Solution (in PYTHON3):
s=input() n=int(input()) s1=s[0] s2=s[2] if(s2=='v'): s2=118 if(s2=='<'): s2=60 if(s2=='^'): s2=94 if(s2=='>'): s2=62 if(s1=='v'): s1=118 if(s1=='<'): s1=60 if(s1=='^'): s1=94 if(s1=='>'): s1=62 k=0 p=0 t=0 if(n%4==0): t=1 print("undefined") n1=n%4 n=n1 if(s1==118): if(n1==1 and s2==60): k=1 if(n==2 and s2==94): k=1 if(n==3 and s2==62): k=1 if(s1==60): if(n1==1 and s2==94): k=1 if(n==2 and s2==62): k=1 if(n==3 and s2==118): k=1 if(s1==94): if(n1==1 and s2==62): k=1 if(n==2 and s2==118): k=1 if(n==3 and s2==60): k=1 if(s1==62): if(n1==1 and s2==118): k=1 if(n==2 and s2==60): k=1 if(n==3 and s2==94): k=1 if(s1==62): if(n1==1 and s2==94): p=1 if(n==2 and s2==60): p=1 if(n==3 and s2==118): p=1 if(s1==94): if(n1==1 and s2==60): p=1 if(n==2 and s2==118): p=1 if(n==3 and s2==62): p=1 if(s1==60): if(n1==1 and s2==118): p=1 if(n==2 and s2==62): p=1 if(n==3 and s2==94): p=1 if(s1==118): if(n1==1 and s2==62): p=1 if(n==2 and s2==94): p=1 if(n==3 and s2==60): p=1 if(t==0): if(k==0 and p==0): print("undefined") if(k==1 and p==1): print("undefined") if(k==1 and p==0): print("cw") if(p==1 and k==0): print("ccw")
Problem: <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 Solution (in PYTHON3):
arr=list(input().strip().split()) n=int(input()) d={"^":0,"<":1,"v":2,">":3} if arr[0]==arr[1] or ((d[arr[0]]+n)%4==d[arr[1]] and (d[arr[1]]+n)%4==d[arr[0]]): print("undefined") elif (d[arr[0]]+n)%4==d[arr[1]]: print("ccw") elif (d[arr[1]]+n)%4==d[arr[0]]: print("cw") else: print("undefined")
Problem: <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 Solution (in CPP):
#include <bits/stdc++.h> using namespace std; char next_clock(char current) { if (current == 'v') return '<'; if (current == '<') return '^'; if (current == '^') return '>'; if (current == '>') return 'v'; } char prev_clock(char current) { if (current == 'v') return '>'; if (current == '>') return '^'; if (current == '^') return '<'; if (current == '<') return 'v'; } int main() { ios::sync_with_stdio(0); int n; char start, end; scanf("%c %c\n", &start, &end); scanf("%d", &n); n = n % 4; char clock = start; char counter = start; for (int i = 0; i < n; ++i) { clock = next_clock(clock); counter = prev_clock(counter); } if (clock == end && counter != end) { printf("cw\n"); } else if (counter == end && clock != end) { printf("ccw\n"); } else { printf("undefined\n"); } return 0; }
Problem: <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 Solution (in PYTHON3):
import sys def f(cc): if ord(cc) == 118 : return 0 elif ord(cc) == 60 : return 1 elif ord(cc) == 94 : return 2 elif ord(cc) == 62 : return 3 for word in sys.stdin: word = list(word) a, b = word[0], word[2] n = int(input()) ss = "" tmp1 = (f(a) + n) % 4 tmp2 = (f(a) - n) % 4 if tmp1 == tmp2 : ss = "undefined" else: if tmp1 == f(b): ss = "cw" else: if tmp2 == f(b): ss = "ccw" print(ss)
Problem: <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 Solution (in JAVA):
import java.util.*; public class Solution{ public static void main(String[] args){ Scanner s=new Scanner(System.in); String s1=s.nextLine(); int n=s.nextInt(); char ch[]={'^','>','v','<'}; int p1=0,p2=0; for(int i=0;i<4;i++){ if(ch[i]==s1.charAt(0)) p1=i; if(ch[i]==s1.charAt(2)) p2=i; } int step=n%4; if(step!=0 && step!=2){ if(ch[(p1+step)%4]==ch[p2]){ System.out.println("cw"); } else if(ch[Math.abs(p2+step)%4]==ch[p1]) System.out.println("ccw"); else System.out.println("undefined"); } else System.out.println("undefined"); } }
Problem: <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 Solution (in JAVA):
import java.util.Scanner; /** * Created by BK on 30-07-2017. */ public class Spinner { public static void main(String... args) { Scanner sc = new Scanner(System.in); char[] positions = {'v', '<', '^', '>'}; char[] posback = {'>', '^', '<', 'v'}; char first = sc.next().charAt(0), second = sc.next().charAt(0); int pos1 = 0, pos2 = 0; for (int i = 0; i < positions.length; i++) { if (first == positions[i]) pos1 = i; } for (int i = 0; i < positions.length; i++) { if (first == posback[i]) pos2 = i; } int n = sc.nextInt(); char forward = positions[(n+pos1) % positions.length]; char backward = posback[(n+pos2) % positions.length]; if (forward==backward) { System.out.println("undefined"); } else if (forward==second) { System.out.println("cw"); } else if (backward==second) { System.out.println("ccw"); } else { System.out.println("undefined"); } } }
Problem: <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 Solution (in CPP):
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); char a, b; cin >> a >> b; int n; cin >> n; map<char, char> m; m['^'] = '>'; m['>'] = 'v'; m['v'] = '<'; m['<'] = '^'; int t = n % 4; int k = 0; while (a != b) { k++; a = m[a]; } if (k == t && t != 2 && t != 0) cout << "cw" << '\n'; else if (4 - k == t && t != 2 && t != 0) cout << "ccw" << '\n'; else cout << "undefined" << '\n'; return 0; }
Problem: <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 Solution (in JAVA):
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.AbstractMap; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Comparator; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.NoSuchElementException; import java.util.Set; import java.util.SortedMap; import java.util.SortedSet; import java.util.Stack; import java.util.StringTokenizer; import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Stream; public class A_426 { public static final long[] POWER2 = generatePOWER2(); public static final IteratorBuffer<Long> ITERATOR_BUFFER_PRIME = new IteratorBuffer<>(streamPrime(1000000).iterator()); private static BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); private static StringTokenizer stringTokenizer = null; private static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); interface BiFunctionResult<Type0, Type1, TypeResult> { TypeResult apply(Type0 x0, Type1 x1, TypeResult x2); } static class Array<Type> implements Iterable<Type> { private Object[] array; public Array(int size) { this.array = new Object[size]; } public Array(int size, Type element) { this(size); Arrays.fill(this.array, element); } public Array(Array<Type> array, Type element) { this(array.size() + 1); for (int index = 0; index < array.size(); index++) { set(index, array.get(index)); } set(size() - 1, element); } public Array(List<Type> list) { this(list.size()); int index = 0; for (Type element : list) { set(index, element); index += 1; } } public Type get(int index) { return (Type) this.array[index]; } public Array set(int index, Type value) { this.array[index] = value; return this; } public int size() { return this.array.length; } public List<Type> toList() { List<Type> result = new ArrayList<>(); for (Type element : this) { result.add(element); } return result; } @Override public Iterator<Type> iterator() { return new Iterator<Type>() { int index = 0; @Override public boolean hasNext() { return this.index < size(); } @Override public Type next() { Type result = Array.this.get(index); index += 1; return result; } }; } @Override public String toString() { return "[" + A_426.toString(this, ", ") + "]"; } } static abstract class Edge<TypeVertex extends Vertex<TypeVertex, TypeEdge>, TypeEdge extends Edge<TypeVertex, TypeEdge>> { public final TypeVertex vertex0; public final TypeVertex vertex1; public final boolean bidirectional; public Edge(TypeVertex vertex0, TypeVertex vertex1, boolean bidirectional) { this.vertex0 = vertex0; this.vertex1 = vertex1; this.bidirectional = bidirectional; this.vertex0.edges.add(getThis()); if (this.bidirectional) { this.vertex1.edges.add(getThis()); } } public TypeVertex other(Vertex<TypeVertex, TypeEdge> vertex) { TypeVertex result; if (vertex0 == vertex) { result = vertex1; } else { result = vertex0; } return result; } public abstract TypeEdge getThis(); public void remove() { this.vertex0.edges.remove(getThis()); if (this.bidirectional) { this.vertex1.edges.remove(getThis()); } } @Override public String toString() { return this.vertex0 + "->" + this.vertex1; } } public static class EdgeDefault<TypeVertex extends Vertex<TypeVertex, EdgeDefault<TypeVertex>>> extends Edge<TypeVertex, EdgeDefault<TypeVertex>> { public EdgeDefault(TypeVertex vertex0, TypeVertex vertex1, boolean bidirectional) { super(vertex0, vertex1, bidirectional); } @Override public EdgeDefault<TypeVertex> getThis() { return this; } } public static class Vertex<TypeVertex extends Vertex<TypeVertex, TypeEdge>, TypeEdge extends Edge<TypeVertex, TypeEdge>> implements Comparable<Vertex<? super TypeVertex, ? super TypeEdge>> { public static <TypeVertex extends Vertex<TypeVertex, TypeEdge>, TypeEdge extends Edge<TypeVertex, TypeEdge>> void depthFirstSearch( Array<TypeVertex> vertices, int indexVertexStart, BiConsumer<TypeVertex, TypeEdge> functionPreVisit, BiConsumer<TypeVertex, TypeEdge> functionInVisit, BiConsumer<TypeVertex, TypeEdge> functionPostVisit ) { TypeVertex vertexTo; TypeEdge edgeTo; boolean[] isOnStack = new boolean[vertices.size()]; Stack<Operation> stackOperations = new Stack<>(); Stack<TypeVertex> stackVertices = new Stack<>(); Stack<TypeEdge> stackEdges = new Stack<>(); TypeVertex vertexStart = vertices.get(indexVertexStart); stackOperations.push(Operation.EXPAND); stackVertices.push(vertexStart); stackEdges.push(null); isOnStack[vertexStart.index] = true; while (!stackOperations.isEmpty()) { Operation operation = stackOperations.pop(); TypeVertex vertex = stackVertices.pop(); TypeEdge edge = stackEdges.pop(); switch (operation) { case INVISIT: functionInVisit.accept(vertex, edge); break; case POSTVISIT: functionPostVisit.accept(vertex, edge); break; case EXPAND: stackOperations.push(Operation.POSTVISIT); stackVertices.push(vertex); stackEdges.push(edge); Integer indexTo = null; for (int index = 0; indexTo == null && index < vertex.edges.size(); index++) { edgeTo = vertex.edges.get(index); vertexTo = edgeTo.other(vertex); if (!isOnStack[vertexTo.index]) { indexTo = index; } } if (indexTo != null) { edgeTo = vertex.edges.get(indexTo); vertexTo = edgeTo.other(vertex); stackOperations.push(Operation.EXPAND); stackVertices.push(vertexTo); stackEdges.push(edgeTo); isOnStack[vertexTo.index] = true; for (int index = indexTo + 1; index < vertex.edges.size(); index++) { edgeTo = vertex.edges.get(index); vertexTo = edgeTo.other(vertex); if (!isOnStack[vertexTo.index]) { stackOperations.push(Operation.INVISIT); stackVertices.push(vertex); stackEdges.push(edge); stackOperations.push(Operation.EXPAND); stackVertices.push(vertexTo); stackEdges.push(edgeTo); isOnStack[vertexTo.index] = true; } } } functionPreVisit.accept(vertex, edge); break; } } } public static <TypeVertex extends Vertex<TypeVertex, TypeEdge>, TypeEdge extends Edge<TypeVertex, TypeEdge>> void depthFirstSearch( Array<TypeVertex> vertices, int indexVertexStart, Consumer<TypeVertex> functionPreVisit, Consumer<TypeVertex> functionInVisit, Consumer<TypeVertex> functionPostVisit ) { depthFirstSearch( vertices, indexVertexStart, (vertex, edge) -> functionPreVisit.accept(vertex), (vertex, edge) -> functionInVisit.accept(vertex), (vertex, edge) -> functionPostVisit.accept(vertex) ); } public static <TypeVertex extends Vertex<TypeVertex, TypeEdge>, TypeEdge extends Edge<TypeVertex, TypeEdge>, TypeResult> TypeResult breadthFirstSearch( TypeVertex vertex, TypeEdge edge, BiFunctionResult<TypeVertex, TypeEdge, TypeResult> function, Array<Boolean> visited, FIFO<TypeVertex> verticesNext, FIFO<TypeEdge> edgesNext, TypeResult result ) { if (!visited.get(vertex.index)) { visited.set(vertex.index, true); result = function.apply(vertex, edge, result); for (TypeEdge edgeNext : vertex.edges) { TypeVertex vertexNext = edgeNext.other(vertex); if (!visited.get(vertexNext.index)) { verticesNext.push(vertexNext); edgesNext.push(edgeNext); } } } return result; } public static <TypeVertex extends Vertex<TypeVertex, TypeEdge>, TypeEdge extends Edge<TypeVertex, TypeEdge>, TypeResult> TypeResult breadthFirstSearch( Array<TypeVertex> vertices, int indexVertexStart, BiFunctionResult<TypeVertex, TypeEdge, TypeResult> function, TypeResult result ) { Array<Boolean> visited = new Array<>(vertices.size(), false); FIFO<TypeVertex> verticesNext = new FIFO<>(); verticesNext.push(vertices.get(indexVertexStart)); FIFO<TypeEdge> edgesNext = new FIFO<>(); edgesNext.push(null); while (!verticesNext.isEmpty()) { result = breadthFirstSearch(verticesNext.pop(), edgesNext.pop(), function, visited, verticesNext, edgesNext, result); } return result; } public final int index; public final List<TypeEdge> edges; public Vertex(int index) { this.index = index; this.edges = new ArrayList<>(); } @Override public int compareTo(Vertex<? super TypeVertex, ? super TypeEdge> that) { return Integer.compare(this.index, that.index); } @Override public String toString() { return "" + this.index; } enum Operation { INVISIT, POSTVISIT, EXPAND } } public static class VertexDefault<TypeEdge extends Edge<VertexDefault<TypeEdge>, TypeEdge>> extends Vertex<VertexDefault<TypeEdge>, TypeEdge> { public VertexDefault(int index) { super(index); } } public static class VertexDefaultDefault extends Vertex<VertexDefaultDefault, EdgeDefaultDefault> { public static Array<VertexDefaultDefault> vertices(int n) { Array<VertexDefaultDefault> result = new Array<>(n); for (int index = 0; index < n; index++) { result.set(index, new VertexDefaultDefault(index)); } return result; } public VertexDefaultDefault(int index) { super(index); } } public static class EdgeDefaultDefault extends Edge<VertexDefaultDefault, EdgeDefaultDefault> { public EdgeDefaultDefault(VertexDefaultDefault vertex0, VertexDefaultDefault vertex1, boolean bidirectional) { super(vertex0, vertex1, bidirectional); } @Override public EdgeDefaultDefault getThis() { return this; } } public static class Tuple2<Type0, Type1> { public final Type0 v0; public final Type1 v1; public Tuple2(Type0 v0, Type1 v1) { this.v0 = v0; this.v1 = v1; } @Override public String toString() { return "(" + this.v0 + ", " + this.v1 + ")"; } } static class Wrapper<Type> { public Type value; public Wrapper(Type value) { this.value = value; } public Type get() { return this.value; } public void set(Type value) { this.value = value; } @Override public String toString() { return this.value.toString(); } } public static class Tuple3<Type0, Type1, Type2> { public final Type0 v0; public final Type1 v1; public final Type2 v2; public Tuple3(Type0 v0, Type1 v1, Type2 v2) { this.v0 = v0; this.v1 = v1; this.v2 = v2; } @Override public String toString() { return "(" + this.v0 + ", " + this.v1 + ", " + this.v2 + ")"; } } public static class Tuple2Comparable<Type0 extends Comparable<? super Type0>, Type1 extends Comparable<? super Type1>> extends Tuple2<Type0, Type1> implements Comparable<Tuple2Comparable<Type0, Type1>> { public Tuple2Comparable(Type0 v0, Type1 v1) { super(v0, v1); } @Override public int compareTo(Tuple2Comparable<Type0, Type1> that) { int result = this.v0.compareTo(that.v0); if (result == 0) { result = this.v1.compareTo(that.v1); } return result; } } public static class SingleLinkedList<Type> { public final Type element; public SingleLinkedList<Type> next; public SingleLinkedList(Type element, SingleLinkedList<Type> next) { this.element = element; this.next = next; } public void toCollection(Collection<Type> collection) { if (this.next != null) { this.next.toCollection(collection); } collection.add(this.element); } } public static class Node<Type> { public static <Type> Node<Type> balance(Node<Type> result) { while (result != null && 1 < Math.abs(height(result.left) - height(result.right))) { if (height(result.left) < height(result.right)) { Node<Type> right = result.right; if (height(right.right) < height(right.left)) { result = new Node<>(result.value, result.left, right.rotateRight()); } result = result.rotateLeft(); } else { Node<Type> left = result.left; if (height(left.left) < height(left.right)) { result = new Node<>(result.value, left.rotateLeft(), result.right); } result = result.rotateRight(); } } return result; } public static <Type> Node<Type> clone(Node<Type> result) { if (result != null) { result = new Node<>(result.value, clone(result.left), clone(result.right)); } return result; } public static <Type> Node<Type> delete(Node<Type> node, Type value, Comparator<? super Type> comparator) { Node<Type> result; if (node == null) { result = null; } else { int compare = comparator.compare(value, node.value); if (compare == 0) { if (node.left == null) { result = node.right; } else { if (node.right == null) { result = node.left; } else { Node<Type> first = first(node.right); result = new Node<>(first.value, node.left, delete(node.right, first.value, comparator)); } } } else { if (compare < 0) { result = new Node<>(node.value, delete(node.left, value, comparator), node.right); } else { result = new Node<>(node.value, node.left, delete(node.right, value, comparator)); } } result = balance(result); } return result; } public static <Type> Node<Type> first(Node<Type> result) { while (result.left != null) { result = result.left; } return result; } public static <Type> Node<Type> get(Node<Type> node, Type value, Comparator<? super Type> comparator) { Node<Type> result; if (node == null) { result = null; } else { int compare = comparator.compare(value, node.value); if (compare == 0) { result = node; } else { if (compare < 0) { result = get(node.left, value, comparator); } else { result = get(node.right, value, comparator); } } } return result; } public static <Type> Node<Type> head(Node<Type> node, Type value, Comparator<? super Type> comparator) { Node<Type> result; if (node == null) { result = null; } else { int compare = comparator.compare(value, node.value); if (compare == 0) { result = node.left; } else { if (compare < 0) { result = head(node.left, value, comparator); } else { result = new Node<>(node.value, node.left, head(node.right, value, comparator)); } } result = balance(result); } return result; } public static int height(Node node) { return node == null ? 0 : node.height; } public static <Type> Node<Type> insert(Node<Type> node, Type value, Comparator<? super Type> comparator) { Node<Type> result; if (node == null) { result = new Node<>(value, null, null); } else { int compare = comparator.compare(value, node.value); if (compare == 0) { result = new Node<>(value, node.left, node.right); ; } else { if (compare < 0) { result = new Node<>(node.value, insert(node.left, value, comparator), node.right); } else { result = new Node<>(node.value, node.left, insert(node.right, value, comparator)); } } result = balance(result); } return result; } public static <Type> Node<Type> last(Node<Type> result) { while (result.right != null) { result = result.right; } return result; } public static int size(Node node) { return node == null ? 0 : node.size; } public static <Type> Node<Type> tail(Node<Type> node, Type value, Comparator<? super Type> comparator) { Node<Type> result; if (node == null) { result = null; } else { int compare = comparator.compare(value, node.value); if (compare == 0) { result = new Node<>(node.value, null, node.right); } else { if (compare < 0) { result = new Node<>(node.value, tail(node.left, value, comparator), node.right); } else { result = tail(node.right, value, comparator); } } result = balance(result); } return result; } public static <Type> void traverseOrderIn(Node<Type> node, Consumer<Type> consumer) { if (node != null) { traverseOrderIn(node.left, consumer); consumer.accept(node.value); traverseOrderIn(node.right, consumer); } } public final Type value; public final Node<Type> left; public final Node<Type> right; public final int size; private final int height; public Node(Type value, Node<Type> left, Node<Type> right) { this.value = value; this.left = left; this.right = right; this.size = 1 + size(left) + size(right); this.height = 1 + Math.max(height(left), height(right)); } public Node<Type> rotateLeft() { Node<Type> left = new Node<>(this.value, this.left, this.right.left); return new Node<>(this.right.value, left, this.right.right); } public Node<Type> rotateRight() { Node<Type> right = new Node<>(this.value, this.left.right, this.right); return new Node<>(this.left.value, this.left.left, right); } } public static class SortedSetAVL<Type> implements SortedSet<Type> { public Comparator<? super Type> comparator; public Node<Type> root; private SortedSetAVL(Comparator<? super Type> comparator, Node<Type> root) { this.comparator = comparator; this.root = root; } public SortedSetAVL(Comparator<? super Type> comparator) { this(comparator, null); } public SortedSetAVL(Collection<? extends Type> collection, Comparator<? super Type> comparator) { this(comparator, null); this.addAll(collection); } public SortedSetAVL(SortedSetAVL<Type> sortedSetAVL) { this(sortedSetAVL.comparator, Node.clone(sortedSetAVL.root)); } @Override public void clear() { this.root = null; } @Override public Comparator<? super Type> comparator() { return this.comparator; } public Type get(Type value) { Node<Type> node = Node.get(this.root, value, this.comparator); return node == null ? null : node.value; } @Override public SortedSetAVL<Type> subSet(Type valueStart, Type valueEnd) { return tailSet(valueStart).headSet(valueEnd); } @Override public SortedSetAVL<Type> headSet(Type valueEnd) { return new SortedSetAVL<>(this.comparator, Node.head(this.root, valueEnd, this.comparator)); } @Override public SortedSetAVL<Type> tailSet(Type valueStart) { return new SortedSetAVL<>(this.comparator, Node.tail(this.root, valueStart, this.comparator)); } @Override public Type first() { return Node.first(this.root).value; } @Override public Type last() { return Node.last(this.root).value; } @Override public int size() { return this.root == null ? 0 : this.root.size; } @Override public boolean isEmpty() { return this.root == null; } @Override public boolean contains(Object value) { return Node.get(this.root, (Type) value, this.comparator) != null; } @Override public Iterator<Type> iterator() { Stack<Node<Type>> path = new Stack<>(); return new Iterator<Type>() { { push(SortedSetAVL.this.root); } public void push(Node<Type> node) { while (node != null) { path.push(node); node = node.left; } } @Override public boolean hasNext() { return !path.isEmpty(); } @Override public Type next() { if (path.isEmpty()) { throw new NoSuchElementException(); } else { Node<Type> node = path.peek(); Type result = node.value; if (node.right != null) { push(node.right); } else { do { node = path.pop(); } while (!path.isEmpty() && path.peek().right == node); } return result; } } }; } @Override public Object[] toArray() { List<Object> list = new ArrayList<>(); Node.traverseOrderIn(this.root, list::add); return list.toArray(); } @Override public <T> T[] toArray(T[] ts) { throw new UnsupportedOperationException(); } @Override public boolean add(Type value) { int sizeBefore = size(); this.root = Node.insert(this.root, value, this.comparator); return sizeBefore != size(); } @Override public boolean remove(Object value) { int sizeBefore = size(); this.root = Node.delete(this.root, (Type) value, this.comparator); return sizeBefore != size(); } @Override public boolean containsAll(Collection<?> collection) { return collection.stream() .allMatch(this::contains); } @Override public boolean addAll(Collection<? extends Type> collection) { return collection.stream() .map(this::add) .reduce(true, (x, y) -> x | y); } @Override public boolean retainAll(Collection<?> collection) { SortedSetAVL<Type> set = new SortedSetAVL<>(this.comparator); collection.stream() .map(element -> (Type) element) .filter(this::contains) .forEach(set::add); boolean result = size() != set.size(); this.root = set.root; return result; } @Override public boolean removeAll(Collection<?> collection) { return collection.stream() .map(this::remove) .reduce(true, (x, y) -> x | y); } @Override public String toString() { return "{" + A_426.toString(this, ", ") + "}"; } } public static class SortedMapAVL<TypeKey, TypeValue> implements SortedMap<TypeKey, TypeValue> { public final Comparator<? super TypeKey> comparator; public final SortedSetAVL<Entry<TypeKey, TypeValue>> entrySet; public SortedMapAVL(Comparator<? super TypeKey> comparator) { this(comparator, new SortedSetAVL<>((entry0, entry1) -> comparator.compare(entry0.getKey(), entry1.getKey()))); } private SortedMapAVL(Comparator<? super TypeKey> comparator, SortedSetAVL<Entry<TypeKey, TypeValue>> entrySet) { this.comparator = comparator; this.entrySet = entrySet; } @Override public Comparator<? super TypeKey> comparator() { return this.comparator; } @Override public SortedMapAVL<TypeKey, TypeValue> subMap(TypeKey keyStart, TypeKey keyEnd) { return new SortedMapAVL<>(this.comparator, this.entrySet.subSet(new AbstractMap.SimpleEntry<>(keyStart, null), new AbstractMap.SimpleEntry<>(keyEnd, null))); } @Override public SortedMapAVL<TypeKey, TypeValue> headMap(TypeKey keyEnd) { return new SortedMapAVL<>(this.comparator, this.entrySet.headSet(new AbstractMap.SimpleEntry<>(keyEnd, null))); } @Override public SortedMapAVL<TypeKey, TypeValue> tailMap(TypeKey keyStart) { return new SortedMapAVL<>(this.comparator, this.entrySet.tailSet(new AbstractMap.SimpleEntry<>(keyStart, null))); } public Entry<TypeKey, TypeValue> firstEntry() { return this.entrySet.first(); } @Override public TypeKey firstKey() { return firstEntry().getKey(); } public Entry<TypeKey, TypeValue> lastEntry() { return this.entrySet.last(); } @Override public TypeKey lastKey() { return lastEntry().getKey(); } @Override public int size() { return this.entrySet().size(); } @Override public boolean isEmpty() { return this.entrySet.isEmpty(); } @Override public boolean containsKey(Object key) { return this.entrySet().contains(new AbstractMap.SimpleEntry<>((TypeKey) key, null)); } @Override public boolean containsValue(Object value) { throw new UnsupportedOperationException(); } @Override public TypeValue get(Object key) { Entry<TypeKey, TypeValue> entry = new AbstractMap.SimpleEntry<>((TypeKey) key, null); entry = this.entrySet.get(entry); return entry == null ? null : entry.getValue(); } @Override public TypeValue put(TypeKey key, TypeValue value) { TypeValue result = get(key); Entry<TypeKey, TypeValue> entry = new AbstractMap.SimpleEntry<>(key, value); this.entrySet().add(entry); return result; } @Override public TypeValue remove(Object key) { TypeValue result = get(key); Entry<TypeKey, TypeValue> entry = new AbstractMap.SimpleEntry<>((TypeKey) key, null); this.entrySet.remove(entry); return result; } @Override public void putAll(Map<? extends TypeKey, ? extends TypeValue> map) { map.entrySet() .forEach(entry -> put(entry.getKey(), entry.getValue())); } @Override public void clear() { this.entrySet.clear(); } @Override public Set<TypeKey> keySet() { throw new UnsupportedOperationException(); } @Override public Collection<TypeValue> values() { return new Collection<TypeValue>() { @Override public int size() { return SortedMapAVL.this.entrySet.size(); } @Override public boolean isEmpty() { return SortedMapAVL.this.entrySet.isEmpty(); } @Override public boolean contains(Object value) { throw new UnsupportedOperationException(); } @Override public Iterator<TypeValue> iterator() { return new Iterator<TypeValue>() { Iterator<Entry<TypeKey, TypeValue>> iterator = SortedMapAVL.this.entrySet.iterator(); @Override public boolean hasNext() { return this.iterator.hasNext(); } @Override public TypeValue next() { return this.iterator.next().getValue(); } }; } @Override public Object[] toArray() { throw new UnsupportedOperationException(); } @Override public <T> T[] toArray(T[] ts) { throw new UnsupportedOperationException(); } @Override public boolean add(TypeValue typeValue) { throw new UnsupportedOperationException(); } @Override public boolean remove(Object o) { throw new UnsupportedOperationException(); } @Override public boolean containsAll(Collection<?> collection) { throw new UnsupportedOperationException(); } @Override public boolean addAll(Collection<? extends TypeValue> collection) { throw new UnsupportedOperationException(); } @Override public boolean removeAll(Collection<?> collection) { throw new UnsupportedOperationException(); } @Override public boolean retainAll(Collection<?> collection) { throw new UnsupportedOperationException(); } @Override public void clear() { throw new UnsupportedOperationException(); } }; } @Override public SortedSetAVL<Entry<TypeKey, TypeValue>> entrySet() { return this.entrySet; } @Override public String toString() { return this.entrySet().toString(); } } public static class FIFO<Type> { public SingleLinkedList<Type> start; public SingleLinkedList<Type> end; public FIFO() { this.start = null; this.end = null; } public boolean isEmpty() { return this.start == null; } public Type peek() { return this.start.element; } public Type pop() { Type result = this.start.element; this.start = this.start.next; return result; } public void push(Type element) { SingleLinkedList<Type> list = new SingleLinkedList<>(element, null); if (this.start == null) { this.start = list; this.end = list; } else { this.end.next = list; this.end = list; } } } public static class MapCount<Type> extends SortedMapAVL<Type, Long> { private int count; public MapCount(Comparator<? super Type> comparator) { super(comparator); this.count = 0; } public long add(Type key, Long delta) { long result; if (delta > 0) { Long value = get(key); if (value == null) { value = delta; } else { value += delta; } put(key, value); result = delta; } else { result = 0; } this.count += result; return result; } public int count() { return this.count; } public List<Type> flatten() { List<Type> result = new ArrayList<>(); for (Entry<Type, Long> entry : entrySet()) { for (long index = 0; index < entry.getValue(); index++) { result.add(entry.getKey()); } } return result; } @Override public void putAll(Map<? extends Type, ? extends Long> map) { throw new UnsupportedOperationException(); } @Override public Long remove(Object key) { Long result = super.remove(key); this.count -= result; return result; } public long remove(Type key, Long delta) { long result; if (delta > 0) { Long value = get(key) - delta; if (value <= 0) { result = delta + value; remove(key); } else { result = delta; put(key, value); } } else { result = 0; } this.count -= result; return result; } @Override public SortedMapAVL<Type, Long> subMap(Type keyStart, Type keyEnd) { throw new UnsupportedOperationException(); } @Override public SortedMapAVL<Type, Long> headMap(Type keyEnd) { throw new UnsupportedOperationException(); } @Override public SortedMapAVL<Type, Long> tailMap(Type keyStart) { throw new UnsupportedOperationException(); } } public static class MapSet<TypeKey, TypeValue> extends SortedMapAVL<TypeKey, SortedSetAVL<TypeValue>> implements Iterable<TypeValue> { private Comparator<? super TypeValue> comparatorValue; public MapSet(Comparator<? super TypeKey> comparatorKey, Comparator<? super TypeValue> comparatorValue) { super(comparatorKey); this.comparatorValue = comparatorValue; } public MapSet(Comparator<? super TypeKey> comparatorKey, SortedSetAVL<Entry<TypeKey, SortedSetAVL<TypeValue>>> entrySet, Comparator<? super TypeValue> comparatorValue) { super(comparatorKey, entrySet); this.comparatorValue = comparatorValue; } public TypeValue firstValue() { TypeValue result; Entry<TypeKey, SortedSetAVL<TypeValue>> firstEntry = firstEntry(); if (firstEntry == null) { result = null; } else { result = firstEntry.getValue().first(); } return result; } public Iterator<TypeValue> iterator() { return new Iterator<TypeValue>() { Iterator<SortedSetAVL<TypeValue>> iteratorValues = values().iterator(); Iterator<TypeValue> iteratorValue = null; @Override public boolean hasNext() { return iteratorValues.hasNext() || (iteratorValue != null && iteratorValue.hasNext()); } @Override public TypeValue next() { if (iteratorValue == null || !iteratorValue.hasNext()) { iteratorValue = iteratorValues.next().iterator(); } return iteratorValue.next(); } }; } public TypeValue lastValue() { TypeValue result; Entry<TypeKey, SortedSetAVL<TypeValue>> lastEntry = lastEntry(); if (lastEntry == null) { result = null; } else { result = lastEntry.getValue().last(); } return result; } public boolean add(TypeKey key, TypeValue value) { SortedSetAVL<TypeValue> set = computeIfAbsent(key, k -> new SortedSetAVL<>(comparatorValue)); return set.add(value); } public boolean removeSet(TypeKey key, TypeValue value) { boolean result; SortedSetAVL<TypeValue> set = get(key); if (set == null) { result = false; } else { result = set.remove(value); if (set.size() == 0) { remove(key); } } return result; } @Override public MapSet<TypeKey, TypeValue> headMap(TypeKey keyEnd) { return new MapSet<>(this.comparator, this.entrySet.headSet(new AbstractMap.SimpleEntry<>(keyEnd, null)), this.comparatorValue); } @Override public MapSet<TypeKey, TypeValue> tailMap(TypeKey keyStart) { return new MapSet<>(this.comparator, this.entrySet.tailSet(new AbstractMap.SimpleEntry<>(keyStart, null)), this.comparatorValue); } } static class IteratorBuffer<Type> { private Iterator<Type> iterator; private List<Type> list; public IteratorBuffer(Iterator<Type> iterator) { this.iterator = iterator; this.list = new ArrayList<Type>(); } public Iterator<Type> iterator() { return new Iterator<Type>() { int index = 0; @Override public boolean hasNext() { return this.index < list.size() || iterator().hasNext(); } @Override public Type next() { if (list.size() <= this.index) { list.add(iterator.next()); } Type result = list.get(index); index += 1; return result; } }; } } public static <Type> List<List<Type>> permutations(List<Type> list) { List<List<Type>> result = new ArrayList<>(); result.add(new ArrayList<>()); for (Type element : list) { List<List<Type>> permutations = result; result = new ArrayList<>(); for (List<Type> permutation : permutations) { for (int index = 0; index <= permutation.size(); index++) { List<Type> permutationNew = new ArrayList<>(permutation); permutationNew.add(index, element); result.add(permutationNew); } } } return result; } public static List<List<Integer>> combinations(int n, int k) { List<List<Integer>> result = new ArrayList<>(); if (k == 0) { } else { if (k == 1) { List<Integer> combination = new ArrayList<>(); combination.add(n); result.add(combination); } else { for (int index = 0; index <= n; index++) { for (List<Integer> combination : combinations(n - index, k - 1)) { combination.add(index); result.add(combination); } } } } return result; } public static <Type> int compare(Iterator<Type> iterator0, Iterator<Type> iterator1, Comparator<Type> comparator) { int result = 0; while (result == 0 && iterator0.hasNext() && iterator1.hasNext()) { result = comparator.compare(iterator0.next(), iterator1.next()); } if (result == 0) { if (iterator1.hasNext()) { result = -1; } else { if (iterator0.hasNext()) { result = 1; } } } return result; } public static <Type> int compare(Iterable<Type> iterable0, Iterable<Type> iterable1, Comparator<Type> comparator) { return compare(iterable0.iterator(), iterable1.iterator(), comparator); } private static String nextString() throws IOException { while ((stringTokenizer == null) || (!stringTokenizer.hasMoreTokens())) { stringTokenizer = new StringTokenizer(bufferedReader.readLine()); } return stringTokenizer.nextToken(); } private static String[] nextStrings(int n) throws IOException { String[] result = new String[n]; { for (int index = 0; index < n; index++) { result[index] = nextString(); } } return result; } public static int nextInt() throws IOException { return Integer.parseInt(nextString()); } public static int[] nextInts(int n) throws IOException { int[] result = new int[n]; { for (int index = 0; index < n; index++) { result[index] = nextInt(); } } return result; } public static double nextDouble() throws IOException { return Double.parseDouble(nextString()); } public static long nextLong() throws IOException { return Long.parseLong(nextString()); } public static long[] nextLongs(int n) throws IOException { long[] result = new long[n]; { for (int index = 0; index < n; index++) { result[index] = nextLong(); } } return result; } public static String nextLine() throws IOException { return bufferedReader.readLine(); } public static void close() { out.close(); } public static int binarySearchMinimum(Function<Integer, Boolean> filter, int start, int end) { int result; if (start == end) { result = end; } else { int middle = start + (end - start) / 2; if (filter.apply(middle)) { result = binarySearchMinimum(filter, start, middle); } else { result = binarySearchMinimum(filter, middle + 1, end); } } return result; } public static int binarySearchMaximum(Function<Integer, Boolean> filter, int start, int end) { return -binarySearchMinimum(x -> filter.apply(-x), -end, -start); } public static long divideCeil(long x, long y) { return (x + y - 1) / y; } public static Set<Long> divisors(long n) { SortedSetAVL<Long> result = new SortedSetAVL<>(Comparator.naturalOrder()); result.add(1L); for (Long factor : factors(n)) { SortedSetAVL<Long> divisors = new SortedSetAVL<>(result); for (Long divisor : result) { divisors.add(divisor * factor); } result = divisors; } return result; } public static long faculty(int n) { long result = 1; for (int index = 2; index <= n; index++) { result *= index; } return result; } public static LinkedList<Long> factors(long n) { LinkedList<Long> result = new LinkedList<>(); Iterator<Long> primes = ITERATOR_BUFFER_PRIME.iterator(); Long prime; while (n > 1 && (prime = primes.next()) * prime <= n) { while (n % prime == 0) { result.add(prime); n /= prime; } } if (n > 1) { result.add(n); } return result; } public static long gcd(long a, long b) { while (a != 0 && b != 0) { if (a > b) { a %= b; } else { b %= a; } } return a + b; } public static long[] generatePOWER2() { long[] result = new long[63]; for (int x = 0; x < result.length; x++) { result[x] = 1L << x; } return result; } public static boolean isPrime(long x) { boolean result = x > 1; Iterator<Long> iterator = ITERATOR_BUFFER_PRIME.iterator(); Long prime; while ((prime = iterator.next()) * prime <= x) { result &= x % prime > 0; } return result; } public static long knapsack(List<Tuple3<Long, Integer, Integer>> itemsValueWeightCount, int weightMaximum) { long[] valuesMaximum = new long[weightMaximum + 1]; for (Tuple3<Long, Integer, Integer> itemValueWeightCount : itemsValueWeightCount) { long itemValue = itemValueWeightCount.v0; int itemWeight = itemValueWeightCount.v1; int itemCount = itemValueWeightCount.v2; for (int weight = weightMaximum; 0 <= weight; weight--) { for (int index = 1; index <= itemCount && 0 <= weight - index * itemWeight; index++) { valuesMaximum[weight] = Math.max(valuesMaximum[weight], valuesMaximum[weight - index * itemWeight] + index * itemValue); } } } long result = 0; for (long valueMaximum : valuesMaximum) { result = Math.max(result, valueMaximum); } return result; } public static boolean knapsackPossible(List<Tuple2<Integer, Integer>> itemsWeightCount, int weightMaximum) { boolean[] weightPossible = new boolean[weightMaximum + 1]; weightPossible[0] = true; int weightLargest = 0; for (Tuple2<Integer, Integer> itemWeightCount : itemsWeightCount) { int itemWeight = itemWeightCount.v0; int itemCount = itemWeightCount.v1; for (int weightStart = 0; weightStart < itemWeight; weightStart++) { int count = 0; for (int weight = weightStart; weight <= weightMaximum && (0 < count || weight <= weightLargest); weight += itemWeight) { if (weightPossible[weight]) { count = itemCount; } else { if (0 < count) { weightPossible[weight] = true; weightLargest = weight; count -= 1; } } } } } return weightPossible[weightMaximum]; } public static long lcm(int a, int b) { return a * b / gcd(a, b); } public static <T> List<T> permutation(long p, List<T> x) { List<T> copy = new ArrayList<>(); for (int index = 0; index < x.size(); index++) { copy.add(x.get(index)); } List<T> result = new ArrayList<>(); for (int indexTo = 0; indexTo < x.size(); indexTo++) { int indexFrom = (int) p % copy.size(); p = p / copy.size(); result.add(copy.remove(indexFrom)); } return result; } public static <Type> String toString(Iterator<Type> iterator, String separator) { StringBuilder stringBuilder = new StringBuilder(); if (iterator.hasNext()) { stringBuilder.append(iterator.next()); } while (iterator.hasNext()) { stringBuilder.append(separator); stringBuilder.append(iterator.next()); } return stringBuilder.toString(); } public static <Type> String toString(Iterator<Type> iterator) { return toString(iterator, " "); } public static <Type> String toString(Iterable<Type> iterable, String separator) { return toString(iterable.iterator(), separator); } public static <Type> String toString(Iterable<Type> iterable) { return toString(iterable, " "); } public static Stream<BigInteger> streamFibonacci() { return Stream.generate(new Supplier<BigInteger>() { private BigInteger n0 = BigInteger.ZERO; private BigInteger n1 = BigInteger.ONE; @Override public BigInteger get() { BigInteger result = n0; n0 = n1; n1 = result.add(n0); return result; } }); } public static Stream<Long> streamPrime(int sieveSize) { return Stream.generate(new Supplier<Long>() { private boolean[] isPrime = new boolean[sieveSize]; private long sieveOffset = 2; private List<Long> primes = new ArrayList<>(); private int index = 0; public void filter(long prime, boolean[] result) { if (prime * prime < this.sieveOffset + sieveSize) { long remainingStart = this.sieveOffset % prime; long start = remainingStart == 0 ? 0 : prime - remainingStart; for (long index = start; index < sieveSize; index += prime) { result[(int) index] = false; } } } public void generatePrimes() { Arrays.fill(this.isPrime, true); this.primes.forEach(prime -> filter(prime, isPrime)); for (int index = 0; index < sieveSize; index++) { if (isPrime[index]) { this.primes.add(this.sieveOffset + index); filter(this.sieveOffset + index, isPrime); } } this.sieveOffset += sieveSize; } @Override public Long get() { while (this.primes.size() <= this.index) { generatePrimes(); } Long result = this.primes.get(this.index); this.index += 1; return result; } }); } public static long totient(long n) { Set<Long> factors = new SortedSetAVL<>(factors(n), Comparator.naturalOrder()); long result = n; for (long p : factors) { result -= result / p; } return result; } public static void main(String[] args) { try { solve(); } catch (IOException exception) { exception.printStackTrace(); } close(); } public static int convert(char c) { int result; switch (c) { case 'v': result = 0; break; case '<': result = 1; break; case '^': result = 2; break; case '>': result = 3; break; default: result = -1; } return result; } public static void solve() throws IOException { int start = convert(nextString().charAt(0)); int end = convert(nextString().charAt(0)); int n = nextInt(); boolean cw = (start + n) % 4 == end; boolean ccw = (start - n + 1000000000) % 4 == end; if (cw) { if (ccw) { out.println("undefined"); } else { out.println("cw"); } } else { out.println("ccw"); } } }
Problem: <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 Solution (in PYTHON3):
s = input() n = int(input())%4 p = {'^':0, '>':1, 'v':2, '<':3} if n%2 == 0: print("undefined") elif(p[s[0]] + n)%4 == p[s[2]]: print("cw") else: print("ccw")
Problem: <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 Solution (in JAVA):
import java.io.*; import java.lang.Math.*; public final class UselessToy{ public static void main(String args[]) throws Exception{ String temp[] = Br.getString().split(" "); char s[] = new char[2]; s[0] = temp[0].charAt(0); s[1] = temp[1].charAt(0); int N = Br.getInt(); char cw[] = {'v', '<', '^', '>'}; char ccw[] = {'>', '^', '<', 'v'}; int cw_start = 0, ccw_start = 0; for(int i=0; i<4; i++){ if(cw[i] == s[0]){ cw_start = i; } } for(int i=0; i<4; i++){ if(ccw[i] == s[0]){ ccw_start = i; } } int cw_end = (cw_start + N) % 4, ccw_end =(ccw_start + N) % 4; if(cw[cw_end] == s[1] && ccw[ccw_end] == s[1]) println("undefined"); else if(cw[cw_end] == s[1]) println("cw"); else if(ccw[ccw_end] == s[1]) println("ccw"); else println("undefined"); } // class for Reader static class Br { final static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static int getInt() throws IOException{ return Integer.parseInt(br.readLine()); } static long getLong() throws IOException{ return Long.parseLong(br.readLine()); } static double getDouble() throws IOException{ return Double.parseDouble(br.readLine()); } static int[] getIntA() throws IOException{ String temp[] = br.readLine().split(" "); int l = temp.length; int a[] = new int[l]; for(int i=0; i<l; i++){ a[i] = Integer.parseInt(temp[i]); } return a; } static int[] getIntA(int l) throws IOException{ String temp[] = br.readLine().split(" "); int a[] = new int[l]; for(int i=0; i<l; i++){ a[i] = Integer.parseInt(temp[i]); } return a; } static long[] getLongA(int l) throws IOException{ String temp[] = br.readLine().split(" "); long a[] = new long[l]; for(int i=0; i<l; i++){ a[i] = Long.parseLong(temp[i]); } return a; } static String getString() throws IOException{ return br.readLine(); } } // class for MaTh libraries static class Mt{ static double precision = 0.00001; static double sqrt(double a){ return newton_raphson(a, a/2); } static double newton_raphson(double a, double guess){ if(guess*guess - a <= precision) return guess; guess = guess - (guess * guess - a)/ (2 * guess); return newton_raphson(a, guess); } static long modPow(long a, long x, long p){ long ans = 1; while(x > 0){ if(x %2 !=0){ ans = (ans*a)%p; } a = (a*a)%p; x/=2; } return (ans%p); } } static<T> void print(T s){ System.out.print(s); } static<T> void println(T s){ System.out.println(s); } }
Problem: <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 Solution (in CPP):
#include <bits/stdc++.h> using namespace std; int main() { char st, en, res, pos; int t; cin >> st >> en >> t; char arr[4] = {'v', '<', '^', '>'}; for (int i = 0; i < 4; i++) { if (st == arr[i]) { pos = i; } } t %= 4; if ((arr[(pos + t) % 4] == en) && (arr[(pos - t + 4) % 4] == en)) { cout << "undefined"; } else if (arr[(pos + t) % 4] == en) { cout << "cw"; } else if (arr[(pos - t + 4) % 4] == en) { cout << "ccw"; } else { cout << "undefined"; } return 0; }
Problem: <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 Solution (in JAVA):
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Reader in = new Reader(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, Reader in, PrintWriter out) { char start = in.nextString().charAt(0); char end = in.nextString().charAt(0); int[][] cw = new int[4][4]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { cw[i][j] = j - i; if (cw[i][j] < 0) { cw[i][j] += 4; } } } int ans = in.nextInt() % 4; if (cw[getIndex(start)][getIndex(end)] == ans && ans != 2 && ans != 0) { out.println("cw"); } else if (Math.abs(4 - cw[getIndex(start)][getIndex(end)]) == ans && ans != 2 && ans != 0) { out.println("ccw"); } else { out.println("undefined"); } } private int getIndex(char start) { if (start == 'v') { return 0; } else if (start == '<') { return 1; } else if (start == '^') { return 2; } else { return 3; } } } static class Reader { private InputStream mIs; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public Reader() { this(System.in); } public Reader(InputStream is) { mIs = is; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = mIs.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public String nextString() { 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 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 boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } } }
Problem: <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 Solution (in CPP):
#include <bits/stdc++.h> using namespace std; map<char, long long> mp, np; vector<pair<int, int>> v; vector<long long> v1; int main() { long long x, y, i, f = 0, r = 0; char m, n; char a[4] = {'^', '>', 'v', '<'}, b[4] = {'^', '<', 'v', '>'}; cin >> m >> n >> x; x %= 4; for (i = 0; i < 4; i++) { if (m == a[i] && a[(x + i) % 4] == n) { f = 1; } if (m == b[i] && b[(x + i) % 4] == n) { r = 1; } } if (f == 1 && r == 0) { cout << "cw"; return 0; } if (r == 1 && f == 0) { cout << "ccw"; return 0; } cout << "undefined"; return 0; }
Problem: <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 Solution (in CPP):
#include <bits/stdc++.h> using namespace std; char c, b; int x1, x2, t, f1, f2; int a[5]; int main() { a[0] = 118, a[1] = 60, a[2] = 94, a[3] = 62; while (cin >> c >> b) { scanf("%d", &t); x1 = int(c); x2 = int(b); for (int i = 0; i < 4; i++) { if (x1 == a[i]) f1 = i; if (x2 == a[i]) f2 = i; } if ((f1 + t) % 4 == f2 && ((f1 - t) % 4 + 4) % 4 == f2) printf("undefined"); else if ((f1 + t) % 4 == f2) printf("cw"); else printf("ccw"); } return 0; }
Problem: <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 Solution (in PYTHON3):
n,m = input().strip().split() #print(n,' ',m) t=int(input()) tr=t % 4 cww=[chr(118), '<',chr(94),'>'] cwww=[chr(118),'>',chr(94),'<'] p=cww.index(n) q=cwww.index(n) #print(p,' ',q) if cww[(p+tr)%4]==cwww[(q+tr)%4]: print('undefined') elif cww[(p+tr)%4]==m: print('cw') elif cwww[(q+tr)%4]==m: print('ccw')
Problem: <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 Solution (in PYTHON3):
s, f = input().split() n = int(input()) spinner = ['v', '<', '^', '>'] # print(spinner) if spinner[(spinner.index(s) + n) % 4] == spinner[(spinner.index(s) - n) % 4] == f: print('undefined') elif spinner[(spinner.index(s) + n) % 4] == f: print('cw') else: print('ccw')
Problem: <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 Solution (in CPP):
#include <bits/stdc++.h> using namespace std; int main() { char a, b; scanf("%c %c", &a, &b); int n; scanf("%d", &n); n %= 4; if (a == '^') { if ((n == 1 && b == '>') || (n == 3 && b == '<')) { printf("cw\n"); } else if (n == 1 && b == '<' || n == 3 && b == '>') { printf("ccw\n"); } else { printf("undefined\n"); } } else if (a == '>') { if (n == 1 && b == 'v' || n == 3 && b == '^') { printf("cw\n"); } else if (n == 1 && b == '^' || n == 3 && b == 'v') { printf("ccw\n"); } else { printf("undefined\n"); } } else if (a == 'v') { if (n == 1 && b == '<' || n == 3 && b == '>') { printf("cw\n"); } else if (n == 1 && b == '>' || n == 3 && b == '<') { printf("ccw\n"); } else { printf("undefined\n"); } } else if (a == '<') { if (n == 1 && b == '^' || n == 3 && b == 'v') { printf("cw\n"); } else if (n == 1 && b == 'v' || n == 3 && b == '^') { printf("ccw\n"); } else { printf("undefined\n"); } } return 0; }
Problem: <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 Solution (in PYTHON3):
a, c, b = list(str(input())) n = int(input()) s = [94, 62, 118, 60] if n % 2 == 0: print("undefined") else: k = s.index(ord(a)) if s[(k + n) % 4] == ord(b): print("cw") else: print("ccw")
Problem: <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 Solution (in CPP):
#include <bits/stdc++.h> using namespace std; int get_pos(char ch) { if (ch == 118) return 0; if (ch == 60) return 1; if (ch == 94) return 2; if (ch == 62) return 3; } int main() { char s_ch, e_ch; int n; cin >> s_ch >> e_ch >> n; int s_i = get_pos(s_ch); int e_i = get_pos(e_ch); int cw = (s_i + n) % 4 == e_i; int ccw = (s_i - e_i + 4) % 4 == n % 4; if (cw && !ccw) { cout << "cw" << endl; } else if (!cw && ccw) { cout << "ccw" << endl; } else { cout << "undefined" << endl; } }
Problem: <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 Solution (in CPP):
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; map<char, int> M; int main() { M['^'] = 0, M['>'] = 1, M['v'] = 2, M['<'] = 3; char beg, end; int n; cin >> beg >> end >> n; n = n % 4; if (abs(M[beg] - M[end]) % 2 == 0 && n % 2 == 0) cout << "undefined" << endl; else if ((M[beg] + n) % 4 == M[end]) cout << "cw" << endl; else cout << "ccw" << endl; }
Problem: <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 Solution (in PYTHON3):
s=input() n=int(input()) if n % 2 ==0: print("undefined") else: a={"118":0,"60":1,"94":2,"62":3} x,y=(a[str(ord(s[0]))]+n)%4, a[str(ord(s[2]))] if x==y: print("cw") else: print("ccw")
Problem: <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 Solution (in JAVA):
import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String args[]) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String in = br.readLine(); int n = Integer.parseInt(br.readLine()); switch(in.charAt(0)) { case '<': switch(in.charAt(2)) { case '>': case '<': System.out.print("undefined"); break; case '^': if(n%4==1) System.out.print("cw"); else { if(n%4==3) System.out.print("ccw"); else System.out.print("undefined"); } break; case 'v': if(n%4==1) System.out.print("ccw"); else { if(n%4==3) System.out.print("cw"); else System.out.print("undefined"); } break; } break; case '^': switch(in.charAt(2)) { case 'v': case '^': System.out.print("undefined"); break; case '>': if(n%4==1) System.out.print("cw"); else { if(n%4==3) System.out.print("ccw"); else System.out.print("undefined"); } break; case '<': if(n%4==1) System.out.print("ccw"); else { if(n%4==3) System.out.print("cw"); else System.out.print("undefined"); } break; } break; case '>': switch(in.charAt(2)) { case '>': case '<': System.out.print("undefined"); break; case 'v': if(n%4==1) System.out.print("cw"); else { if(n%4==3) System.out.print("ccw"); else System.out.print("undefined"); } break; case '^': if(n%4==1) System.out.print("ccw"); else { if(n%4==3) System.out.print("cw"); else System.out.print("undefined"); } break; } break; case 'v': switch(in.charAt(2)) { case '^': case 'v': System.out.print("undefined"); break; case '<': if(n%4==1) System.out.print("cw"); else { if(n%4==3) System.out.print("ccw"); else System.out.print("undefined"); } break; case '>': if(n%4==1) System.out.print("ccw"); else { if(n%4==3) System.out.print("cw"); else System.out.print("undefined"); } break; } break; } } }
Problem: <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 Solution (in JAVA):
import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.InputMismatchException; import java.util.List; public class Main { InputStream is; PrintWriter out; String INPUT = ""; private static final long M = 1000000007L; void solve() { StringBuffer sb = new StringBuffer(); String str = "v<^>"; char s = nc(); char e = nc(); int N = ni() % 4; int d = (str.indexOf(s) - str.indexOf(e) + 4) % 4; // tr(N, d); out.println(d == N && d == 4 - N || d == 0 && N == 0 ? "undefined" : d == N ? "ccw" : d == 4 - N ? "cw" : "undefined"); } private long gcd(long a, long b) { while (a != 0) { long tmp = b % a; b = a; a = tmp; } return b; } void run() throws Exception { is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes()); out = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); out.flush(); if (!INPUT.isEmpty()) tr(System.currentTimeMillis() - s + "ms"); } public static void main(String[] args) throws Exception { new Main().run(); } private byte[] inbuf = new byte[1024]; public int lenbuf = 0, ptrbuf = 0; private boolean vis[]; private int readByte() { if (lenbuf == -1) throw new InputMismatchException(); if (ptrbuf >= lenbuf) { ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) return -1; } return inbuf[ptrbuf++]; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) ; return b; } private double nd() { return Double.parseDouble(ns()); } private char nc() { return (char) skip(); } private String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' // ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while (p < n) { if (!(isSpaceChar(b))) buf[p++] = (char) b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private char[][] nm(int n, int m) { char[][] map = new char[n][]; for (int i = 0; i < n; i++) map[i] = ns(m); return map; } private int[] na(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = ni(); return a; } private String[] nas(int n) { String[] a = new String[n]; for (int i = 0; i < n; i++) a[i] = ns(); return a; } private Integer[] na2(int n) { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = Math.abs(ni()); return a; } private int[][] na(int n, int m) { int[][] a = new int[n][]; for (int i = 0; i < n; i++) a[i] = na(m); return a; } private Integer[][] na2(int n, int m) { Integer[][] a = new Integer[n][]; for (int i = 0; i < n; i++) a[i] = na2(m); return a; } private int ni() { int num = 0, b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } private long nl() { long num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); } }
Problem: <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 Solution (in JAVA):
import java.util.*; import java.io.*; /* < ^ 7 */ public class A { public static void main(String[] args) { Scanner qwe = new Scanner(System.in); String str = "v<^>"; int s = str.indexOf(qwe.next().charAt(0)); int e = str.indexOf(qwe.next().charAt(0)); int n = qwe.nextInt(); int cw = (s+n)%4; int ccw = (s+4-(n%4))%4; if(cw == e && ccw == e){ System.out.println("undefined"); } else{ if(cw == e) System.out.println("cw"); if(ccw == e) System.out.println("ccw"); } qwe.close(); } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(InputStream in) { br = new BufferedReader(new InputStreamReader(in)); st = new StringTokenizer(""); } public String next() throws IOException { while(!st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public void close() throws IOException { br.close(); } } }
Problem: <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 Solution (in PYTHON):
t = map(str, raw_input().strip().split()) pos1cw = '^' pos1ccw = '^' #print pos1cw, pos1ccw pos2 = t[1] #print pos2 n = int(raw_input().strip()) cw = ['^', '>', 'v', '<'] ccw = ['^', '<', 'v', '>'] ind = cw.index(t[0]) pos1cw = cw[(ind + n)%4] ind = ccw.index(t[0]) pos1ccw = ccw[(ind + n)%4] #print pos1cw #print pos1ccw #print pos2, "pos2" if (pos1cw==pos2) and (pos1ccw==pos2): print 'undefined' elif pos1cw == pos2: print "cw" elif pos1ccw == pos2: print 'ccw' else: print 'undefined'
Problem: <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 Solution (in CPP):
#include <bits/stdc++.h> using namespace std; int main() { char c1, c2, left[] = "^<v>", right[] = "^>v<"; int n; cin >> c1 >> c2 >> n; n %= 4; bool Ok1 = 0, Ok2 = 0; for (int i = 0; i < 4; i++) { if (left[i] == c1) { if (left[(i + n) % 4] == c2) { Ok1 = 1; break; } } } for (int i = 0; i < 4; i++) { if (right[i] == c1) { if (right[(i + n) % 4] == c2) { Ok2 = 1; break; } } } if (Ok1 && Ok2) { cout << "undefined"; } else if (Ok1) { cout << "ccw"; } else if (Ok2) { cout << "cw"; } else { cout << "undefined"; } return 0; }
Problem: <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 Solution (in JAVA):
import java.io.*; import java.util.*; public class A { public static void solution(BufferedReader reader, PrintWriter writer) throws IOException { In in = new In(reader); Out out = new Out(writer); String s = "v<^>"; char c1 = in.next().charAt(0), c2 = in.next().charAt(0); int p1 = s.indexOf(c1), p2 = s.indexOf(c2); int n = in.nextInt() % 4; if ((p1 + n) % 4 == p2 && n % 2 != 0) out.println("cw"); else if ((p1 + 4 - n) % 4 == p2 && n % 2 != 0) out.println("ccw"); else out.println("undefined"); } public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader( new InputStreamReader(System.in)); PrintWriter writer = new PrintWriter( new BufferedWriter(new OutputStreamWriter(System.out))); solution(reader, writer); writer.close(); } protected static class In { private BufferedReader reader; private StringTokenizer tokenizer = new StringTokenizer(""); public In(BufferedReader reader) { this.reader = reader; } public String next() throws IOException { while (!tokenizer.hasMoreTokens()) tokenizer = new StringTokenizer(reader.readLine()); return tokenizer.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public int[] nextIntArray1(int n) throws IOException { int[] a = new int[n + 1]; for (int i = 1; i <= n; i++) a[i] = nextInt(); return a; } public int[] nextIntArraySorted(int n) throws IOException { int[] a = nextIntArray(n); Random r = new Random(); for (int i = 0; i < n; i++) { int j = i + r.nextInt(n - i); int t = a[i]; a[i] = a[j]; a[j] = t; } Arrays.sort(a); return a; } public long[] nextLongArray(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public long[] nextLongArray1(int n) throws IOException { long[] a = new long[n + 1]; for (int i = 1; i <= n; i++) a[i] = nextLong(); return a; } public long[] nextLongArraySorted(int n) throws IOException { long[] a = nextLongArray(n); Random r = new Random(); for (int i = 0; i < n; i++) { int j = i + r.nextInt(n - i); long t = a[i]; a[i] = a[j]; a[j] = t; } Arrays.sort(a); return a; } } protected static class Out { private PrintWriter writer; private static boolean local = System .getProperty("ONLINE_JUDGE") == null; public Out(PrintWriter writer) { this.writer = writer; } public void print(char c) { writer.print(c); } public void print(int a) { writer.print(a); } public void printb(int a) { writer.print(a); writer.print(' '); } public void println(Object a) { writer.println(a); } public void println(Object[] os) { for (int i = 0; i < os.length; i++) { writer.print(os[i]); writer.print(' '); } writer.println(); } public void println(int[] a) { for (int i = 0; i < a.length; i++) { writer.print(a[i]); writer.print(' '); } writer.println(); } public void println(long[] a) { for (int i = 0; i < a.length; i++) { writer.print(a[i]); writer.print(' '); } writer.println(); } public void flush() { writer.flush(); } public static void db(Object... objects) { if (local) System.out.println(Arrays.deepToString(objects)); } } }
Problem: <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 Solution (in PYTHON3):
x=input().split() a=x[0] b=x[1] n=int(input()) cw=n%4 ccw=4-cw c=["^",">","v","<"] k=c.index(a) c1=[c[k],c[(k+1)%4],c[(k+2)%4],c[(k+3)%4]] if cw!=ccw and c1[cw]==b: z="cw" elif cw!=ccw and c1[ccw]==b: z="ccw" elif cw==ccw: z="undefined" if n==0: z="undefined" if a==b: z="undefined" print(z)
Problem: <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 Solution (in JAVA):
import java.io.*; import java.util.*; /** * * @author akashvermaofskt * Coding is love <3! */ public class A { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); static StringTokenizer st = null; static String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } static int nextInt() { return Integer.parseInt(next()); } static long nextLong() { return Long.parseLong(next()); } public static void main(String args[]) { try { char A[]={'^','>','v','<'}; char B[]={'^','<','v','>'}; char start=next().charAt(0); char end=next().charAt(0); int s1=0,s2=0; //System.out.println(""+start); switch(start){ case '^': s1=0; s2=0; break; case '>': s1=1; s2=3; break; case 'v': s1=2; s2=2; break; case '<': s1=3; s2=1; break; } int n=nextInt(); int e1=((n)%4 + s1)%4 ; int e2=((n)%4 + s2)%4; //System.out.println("e1 "+e1); //System.out.println("e2 "+e2); if(A[e1]==end && B[e2]!=end){ bw.write("cw\n"); }else if(A[e1]!=end && B[e2]==end){ bw.write("ccw\n"); }else bw.write("undefined\n"); bw.flush(); } catch (Exception e) { e.printStackTrace(); } } }
Problem: <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 Solution (in PYTHON3):
#n = int(input()) #n, m = map(int, input().split()) s = input() #c = list(map(int, input().split())) n = int(input()) a = ['v', '<', '^', '>'] k = n % 4 if k % 2 == 0: print('undefined') elif (a.index(s[2]) - a.index(s[0]) ) % 4 == k: print('cw') else: print('ccw')
Problem: <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 Solution (in PYTHON3):
posiciones = input() tiempo = int(input()) posiciones = posiciones.split(' ') inicio = posiciones[0] final = posiciones[1] dict = ['^','>','v','<'] if tiempo >4: tiempo =tiempo%4 #contando ccw contador_izq = dict.index(inicio) for n in range(tiempo): if contador_izq-1 <0: contador_izq= 3 else: contador_izq -=1 #contando cw contador_der = dict.index(inicio) for n in range(tiempo): if contador_der+1 >3: contador_der= 0 else: contador_der +=1 if (posiciones[1] == dict[contador_izq]) and (posiciones[1] != dict[contador_der]): print('ccw') elif (posiciones[1] != dict[contador_izq]) and (posiciones[1] == dict[contador_der]): print('cw') else: print('undefined')
Problem: <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 Solution (in CPP):
#include <bits/stdc++.h> using namespace std; int main() { char st, en; cin >> st >> en; int n; cin >> n; n = n % 4; char cl, ccl; string cc = "v<^>v"; string ac = "v>^<v"; int ccpos, acpos; for (int i = 0; i < cc.size(); ++i) { if (cc[i] == st) { ccpos = i; } if (ac[i] == st) { acpos = i; } } ccpos = (ccpos + n) % 4; acpos = (acpos + n) % 4; if (cc[ccpos] == en && ac[acpos] != en) { cout << "cw" << endl; } else if (cc[ccpos] != en && ac[acpos] == en) { cout << "ccw" << endl; } else { cout << "undefined" << endl; } return 0; }
Problem: <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 Solution (in PYTHON):
# -*- coding: utf-8 -*- # from __future__ import division import sys a, b = sys.stdin.readline().split() c = int(sys.stdin.readline()) if (c % 2): if (c % 4) == 1: if (a == '<') and (b == '^'): print 'cw' elif (a == '^') and (b == '>'): print 'cw' elif (a == '>') and (b == 'v'): print 'cw' elif (a == 'v') and (b == '<'): print 'cw' elif (a == '<') and (b == 'v'): print 'ccw' elif (a == '^') and (b == '<'): print 'ccw' elif (a == '>') and (b == '^'): print 'ccw' elif (a == 'v') and (b == '>'): print 'ccw' else: if (a == '<') and (b == '^'): print 'ccw' elif (a == '^') and (b == '>'): print 'ccw' elif (a == '>') and (b == 'v'): print 'ccw' elif (a == 'v') and (b == '<'): print 'ccw' elif (a == '<') and (b == 'v'): print 'cw' elif (a == '^') and (b == '<'): print 'cw' elif (a == '>') and (b == '^'): print 'cw' elif (a == 'v') and (b == '>'): print 'cw' else: print 'undefined'
Problem: <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 Solution (in PYTHON3):
def e(d, s): return (s + (c if d else -c)) % 4 p = {'v': 0, '<': 1, '^': 2, '>': 3} i = input().split() p1, p2 = [p[j] for j in i] c = int(input()) r1, r2 = e(1, p1), e(0, p1) if r1 == r2: print('undefined') elif r1 == p2: print('cw') else: print('ccw') ''' > v 1 '''
Problem: <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 Solution (in PYTHON3):
l = list(map(ord, input().split())) n = int(input()) #v < ^ > cw = [118, 60, 94, 62] n = n % 4 ind = cw.index(l[0]) indCw = (n + ind) % 4 indCcw = ind for i in range(n): if indCcw - 1 < 0: indCcw = 3 else: indCcw -= 1 if indCw == indCcw: print("undefined") elif cw[indCw] == l[1]: print("cw") elif cw[indCcw] == l[1]: print("ccw")
Problem: <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 Solution (in JAVA):
import java.util.*; import java.math.*; public class Main { static char[] data = {'v','<','^','>'}; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); char a = scanner.next().charAt(0); char b = scanner.next().charAt(0); int n = scanner.nextInt(); n = n%4; int res1 = 0; int res2 = 0; int st = 0; int ed = 0; for(int i=0;i<data.length;i++){ if(data[i]==a){ st = i; } } int st1 = st; //ι‘Ίζ—Άι’ˆ for(int i=0;i<n;i++){ st1++; if(st1==4){ st1=0; } } if(data[st1]==b){ res1 = 1; //System.out.println("cw"); } st1 = st; //ι€†ζ—Άι’ˆ for(int i=0;i<n;i++){ st1--; if(st1<0){ st1=3; } } if(data[st1]==b){ res2 = 1; //System.out.println("ccw"); } if(res1==1&&res2==1){ System.out.println("undefined"); }else if(res1==1){ System.out.println("cw"); }else if(res2==1){ System.out.println("ccw"); }else{ System.out.println("undefined"); } } }
Problem: <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 Solution (in JAVA):
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; public class TheUselessToy { public static int signToInt(char c) { switch(c) { case 60: return 0; case 94: return 1; case 62: return 2; case 118: return 3; default: return -1; } } public static int intToSign(int c) { switch(c) { case 0: return 60; case 1: return 94; case 2: return 62; case 3: return 118; default: return -1; } } public static void main(String[] args) throws IOException{ // TODO Auto-generated method stub InputStreamReader in = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(in); PrintWriter out = new PrintWriter(System.out); String[] str = br.readLine().split(" "); int rotate = Integer.parseInt(br.readLine()); int sign = signToInt(str[0].charAt(0)); int cw = (sign+rotate)%4; int ccw = (sign+((4-(rotate%4))%4))%4; if(cw==ccw) { out.println("undefined"); } else { if(intToSign(cw)==str[1].charAt(0)) out.println("cw"); else if(intToSign(ccw)==str[1].charAt(0)) out.println("ccw"); else out.println("undefined"); } out.close(); br.close(); } }
Problem: <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 Solution (in PYTHON3):
spins = ["v","<","^",">"] spinner = list(map(str,input().split())) n = int(input()) if n%2 == 0: print("undefined") elif (spins.index(spinner[0])+n)%4 == spins.index(spinner[1]): print("cw") else: print("ccw")
Problem: <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 Solution (in CPP):
#include <bits/stdc++.h> using namespace std; char arrayc[4] = {'^', '>', 'v', '<'}; char arraycc[4] = {'^', '<', 'v', '>'}; char rc(char a, long long n) { if (a == arrayc[0]) return arrayc[((long long)0 + n % (long long)4) % (long long)4]; else if (a == arrayc[1]) return arrayc[((long long)1 + n % (long long)4) % (long long)4]; else if (a == arrayc[2]) return arrayc[((long long)2 + n % (long long)4) % (long long)4]; else if (a == arrayc[3]) return arrayc[((long long)3 + n % (long long)4) % (long long)4]; } char rcc(char a, long long n) { if (a == arraycc[0]) return arraycc[((long long)0 + n % (long long)4) % (long long)4]; else if (a == arraycc[1]) return arraycc[((long long)1 + n % (long long)4) % (long long)4]; else if (a == arraycc[2]) return arraycc[((long long)2 + n % (long long)4) % (long long)4]; else if (a == arraycc[3]) return arraycc[((long long)3 + n % (long long)4) % (long long)4]; } int main() { char a, b; cin >> a >> b; long long c; cin >> c; int flag = 0; if (rc(a, c) == b) flag = 1; else if (rcc(a, c) == b) flag = -1; if (rc(a, c) == rcc(a, c)) flag = 0; if (flag == 1) cout << "cw"; else if (flag == -1) cout << "ccw"; else cout << "undefined"; }
Problem: <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 Solution (in PYTHON):
# coding: utf-8 def index_of(element, list): for i in range(len(list)): if element == list[i]: return i cw = ["v", "<", "^", ">"] ccw = ["v", ">", "^", "<"] positions = raw_input().split() time = int(raw_input()) cw_position = cw[(time + index_of(positions[0], cw)) % 4] ccw_position = ccw[(time + index_of(positions[0], ccw)) % 4] if cw_position == ccw_position: print "undefined" elif cw_position == positions[1]: print "cw" else: print "ccw"
Problem: <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 Solution (in PYTHON3):
def next(shape): if shape == 'v': return '<' elif shape == '<': return '^' elif shape == '^': return '>' else: return 'v' start, end = input().split(' ') n = int(input()) if n % 2 == 0: print('undefined') elif n % 4 == 1: print('cw' if end == next(start) else 'ccw') else: print('cw' if end == next(next(next(start))) else 'ccw')
Problem: <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 Solution (in PYTHON3):
# cook your dish here s=['v','<','^','>'] start,end=input().split() n=int(input()) for i in range(len(s)): if s[i]==start: start=i if s[i]==end: end=i if s[(start+n)%4]==s[(start-n)%4] and s[(start+n)%4]==s[end]: print('undefined') elif s[(start+n)%4]==s[end]: print('cw') elif s[(start-n)%4]==s[end]: print('ccw') else: print('undefined')
Problem: <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 Solution (in PYTHON3):
str1=input("") firststr=str1[0] secondstr=str1[2] num=int(input("")) def switch(x): if x=='v' : return 1 if x=='<' : return 2 if x=='^' : return 3 if x=='>' : return 4 fsn=switch(firststr) ssn=switch(secondstr) output="undefined" num=(num%4) flag1=0 flag2=0 if num==0 : num=4 fsnnum=fsn+num if fsn+num>4 : fsnnum=(fsn+num)-4 if fsnnum==ssn : output="cw" flag1=1 if fsn-num==(-4+ssn) or fsn-num == ssn : output="ccw" flag2=1 if flag1==flag2 : output = "undefined" print(output)
Problem: <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 Solution (in CPP):
#include <bits/stdc++.h> using namespace std; const int N = 500005; int f(char c) { if (c == '^') return 1; if (c == '>') return 2; if (c == 'v') return 3; return 4; } int main() { std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); char a, b; cin >> a >> b; long long n; cin >> n; int x, y; x = f(a); y = f(b); bool ans1 = 0, ans2 = 0; int cw = y - x; if (cw < 0) cw += 4; int ccw = x - y; if (ccw < 0) ccw += 4; if (cw == ccw) cout << "undefined"; else if ((n % 4) == ccw) cout << "ccw"; else if ((n % 4) == cw) cout << "cw"; }
Problem: <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 Solution (in JAVA):
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String start = sc.next(); String end = sc.next(); int sec = sc.nextInt(); String cw = new String("v<^>v<^>v<^>v<^>"); String ccw = new String("v>^<v>^<v<^>v<^>"); if (sec % 2 != 0) { if (cw.charAt(sec % 4 + cw.indexOf(start)) == end.charAt(0)) { System.out.print("cw"); } else if (ccw.charAt(sec % 4 + ccw.indexOf(start)) == end.charAt(0)) { System.out.print("ccw"); } else { System.out.print("undefined"); } } else { System.out.print("undefined"); } } }
Problem: <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 Solution (in CPP):
#include <bits/stdc++.h> using namespace std; int p[5]; int q[5]; char ch1, ch2; int n; int main() { p[1] = 118; p[2] = 60; p[3] = 94; p[0] = 62; q[1] = 118; q[2] = 62; q[3] = 94; q[0] = 60; scanf("%c %c", &ch1, &ch2); scanf("%d", &n); int m = n % 4; int a = int(ch1); int b = int(ch2); int c1; int c2; for (int i = 0; i <= 3; i++) { if (p[i] == a) c1 = i; if (q[i] == a) c2 = i; } c1 += m; c2 += m; c1 %= 4; c2 %= 4; if (p[c1] == b && q[c2] == b) cout << "undefined" << endl; else if (p[c1] == b) cout << "cw" << endl; else if (q[c2] == b) cout << "ccw" << endl; else cout << "undefined" << endl; return 0; }
Problem: <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 Solution (in CPP):
#include <bits/stdc++.h> using namespace std; int main() { int n; map<char, int> d; d['v'] = 0; d['<'] = 1; d['^'] = 2; d['>'] = 3; char st, fin; cin >> st >> fin; cin >> n; int sti = d[st]; int fini = d[fin]; string ans = ""; if ((sti + n) % 4 == fini) ans = "cw"; if ((sti + 1000000000 - n) % 4 == fini) { if (ans != "") { cout << "undefined" << "\n"; return 0; } else { ans = "ccw"; } } cout << ans << "\n"; return 0; }
Problem: <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 Solution (in JAVA):
import javax.print.attribute.standard.MediaPrintableArea; import java.math.BigDecimal; import java.math.BigInteger; import java.math.RoundingMode; import java.io.*; import java.util.*; /** * Created by FirΠ΅fly on 1/1/2017. */ public class Task { public static void main(String[] args) throws IOException { Emaxx emaxx = new Emaxx(); } } class Emaxx { FScanner fs; PrintWriter pw; int n, off, m, k; Integer W; ArrayList<Integer>[] graph; int[][] to; double[] comes, zh; int[] nums, res; LinkedList<Pair> qoue; boolean[] flags; Emaxx() throws IOException { fs = new FScanner(new InputStreamReader(System.in)); // pw = new PrintWriter(new FileWriter("arithnumbers.out")); // fs = new FScanner(new FileReader("C:\\Users\\FirΠ΅fly\\Desktop\\New Text Document.txt")); // fs = new FScanner(new FileReader("input.txt"));; // pw = new PrintWriter("output.txt"); PrintWriter pw = new PrintWriter(System.out); char st = fs.nextChar(); fs.nextChar(); char end = fs.nextChar(); long time = fs.nextLong(); time%=4; if (time == 0 || time == 2) pw.println("undefined"); else if (time == 1){ if (st == 'v') { if (end == '<') pw.println("cw"); else pw.println("ccw"); } else if (st == '<') { if (end == '^') pw.println("cw"); else pw.println("ccw"); } else if (st == '^') { if (end == '>') pw.println("cw"); else pw.println("ccw"); } else if (st == '>') { if (end == 'v') pw.println("cw"); else pw.println("ccw"); } } else { if (st == 'v') { if (end == '<') pw.println("ccw"); else pw.println("cw"); } else if (st == '<') { if (end == '^') pw.println("ccw"); else pw.println("cw"); } else if (st == '^') { if (end == '>') pw.println("ccw"); else pw.println("cw"); } else if (st == '>') { if (end == 'v') pw.println("ccw"); else pw.println("cw"); } } pw.close(); } } class Triple implements Comparable<Triple> { int t, ni, k; Triple(int x1, int y1, int c1) { t = x1; ni = y1; k = c1; } @Override public int compareTo(Triple triple) { return Integer.compare(t, triple.t); } } class Pair implements Comparable<Pair>{ int x, y; Pair(int x1, int y1) {x = x1; y = y1;} Pair(){} @Override public int compareTo(Pair o) { return Integer.compare(x, o.x); } } class Algs { public static int[] Z_f(char[] s) { int[] zf = new int[s.length]; zf[0] = -1; int l = 0, r= 0; for (int i = 1; i<s.length; i++) { if (i>r) { int g = i; while (g < s.length && s[g] == s[g-i]) g++; if (g == i) continue; l = i; r = g-1; zf[i] = g-i; } else { if (zf[i-l]<=r-i+1) zf[i] = zf[i-l]; else { int g = r+1; while (g <s.length && s[g] == s[g-i]) g++; if (g == r+1) zf[i] = r-i+1; else { zf[i] = g-i; r = g-1; l = i; } } } } return zf; } } class FScanner { BufferedReader br; StringTokenizer st; FScanner(InputStreamReader isr) { br = new BufferedReader(isr); } FScanner(FileReader fr) { br = new BufferedReader(fr); } String nextToken() throws IOException{ while (st == null || !st.hasMoreTokens()) { String s = br.readLine(); if (s == null) return null; st = new StringTokenizer(s); } return st.nextToken(); } 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 nextLine() throws IOException { return br.readLine(); } char nextChar() throws IOException { return (char) br.read(); } }
Problem: <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 Solution (in JAVA):
import java.io.*; import java.util.*; public class Solution{ public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String inp = br.readLine(); int n = Integer.parseInt(br.readLine()); char beg = inp.charAt(0), end = inp.charAt(2); n = n % 4; char[] pos = {'^','>','v','<'}; int i=0; while(i < 4 && pos[i] != beg) i++; int j = 0; while(j<4 && pos[j] != end) j++; if((i+n)%4 == j && (i-n+8)%4 != j) System.out.println("cw"); else if((i-n+8)%4 == j && (i+n)%4 != j) System.out.println("ccw"); else System.out.println("undefined"); } }
Problem: <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 Solution (in PYTHON3):
s, e = input().split() states = "^>v<" n = int(input()) if n%2==0: print("undefined") else: if (states.index(e)-states.index(s))%4 == n%4: print("cw") else: print("ccw")
Problem: <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 Solution (in JAVA):
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Div2_426A { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String input = reader.readLine(); int time = Integer.parseInt(reader.readLine()); if (time % 2 == 0) { System.out.println("undefined"); return; } time %= 4; StringTokenizer inputData = new StringTokenizer(input); char p1 = inputData.nextToken().charAt(0); char p2 = inputData.nextToken().charAt(0); int v1 = 0; int v2 = 0; if (p1 == '^') { v1 = 0; } if (p1 == '>') { v1 = 1; } if (p1 == 'v') { v1 = 2; } if (p1 == '<') { v1 = 3; } if (p2 == '^') { v2 = 0; } if (p2 == '>') { v2 = 1; } if (p2 == 'v') { v2 = 2; } if (p2 == '<') { v2 = 3; } if ((v1 + 1) % 4 == v2) { if (time == 1) { System.out.println("cw"); } if (time == 3) { System.out.println("ccw"); } } else { if (time == 1) { System.out.println("ccw"); } if (time == 3) { System.out.println("cw"); } } } }
Problem: <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 Solution (in CPP):
#include <bits/stdc++.h> using namespace std; int main() { char x, y; cin >> x >> y; int n; cin >> n; n = n % 4; if (n == 0 || n == 2) cout << "undefined\n"; else { if (n == 1) { if (x == '^' && y == '>') cout << "cw\n"; else if (x == '^' && y == '<') cout << "ccw\n"; else if (x == '>' && y == 'v') cout << "cw\n"; else if (x == '>' && y == '^') cout << "ccw\n"; else if (x == 'v' && y == '<') cout << "cw\n"; else if (x == 'v' && y == '>') cout << "ccw\n"; else if (x == '<' && y == '^') cout << "cw\n"; else if (x == '<' && y == 'v') cout << "ccw\n"; } else if (n == 3) { if (x == '^' && y == '<') cout << "cw\n"; else if (x == '^' && y == '>') cout << "ccw\n"; else if (x == '>' && y == '^') cout << "cw\n"; else if (x == '>' && y == 'v') cout << "ccw\n"; else if (x == 'v' && y == '>') cout << "cw\n"; else if (x == 'v' && y == '<') cout << "ccw\n"; else if (x == '<' && y == 'v') cout << "cw\n"; else if (x == '<' && y == '^') cout << "ccw\n"; } } return 0; }
Problem: <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 Solution (in CPP):
#include <bits/stdc++.h> void Set_C(char* c) { if (*c == '^') *c = 0; else if (*c == '>') *c = 1; else if (*c == 'v') *c = 2; else *c = 3; } int main(void) { int n, cnt = 0; char c1, c2; scanf(" %c %c", &c1, &c2); scanf("%d", &n); n = n % 4; Set_C(&c1); Set_C(&c2); if ((c1 + n) % 4 == c2) cnt = 2; if ((c1 + (4 - n)) % 4 == c2) { if (cnt == 2) cnt = 0; else cnt = 1; } if (cnt == 1) puts("ccw"); else if (cnt == 2) puts("cw"); else puts("undefined"); return 0; }
Problem: <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 Solution (in CPP):
#include <bits/stdc++.h> using namespace std; int main() { char a, b; int n, i; cin >> a >> b >> n; n = n % 4; bool cw = false, ccw = false; char temp = a; for (i = 0; i < n; i++) { if (temp == '^') temp = '>'; else if (temp == '>') temp = 'v'; else if (temp == 'v') temp = '<'; else if (temp == '<') temp = '^'; } if (temp == b) cw = true; temp = a; for (i = 0; i < n; i++) { if (temp == '^') temp = '<'; else if (temp == '<') temp = 'v'; else if (temp == 'v') temp = '>'; else if (temp == '>') temp = '^'; } if (temp == b) ccw = true; if (cw && ccw) cout << "undefined"; else if (cw) cout << "cw"; else if (ccw) cout << "ccw"; return 0; }
Problem: <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 Solution (in JAVA):
import java.util.Scanner; public class P834A { public static void main(String[] args) { Scanner scan=new Scanner(System.in); char i,f; int n; i=scan.next().charAt(0); f=scan.next().charAt(0); n=scan.nextInt(); n%=4; if(n==0||n==2) System.out.println("undefined"); else if(n==1) { switch(i) { case 'v': if(f=='<') System.out.println("cw"); else System.out.println("ccw"); break; case '<': if(f=='^') System.out.println("cw"); else System.out.println("ccw"); break; case '^': if(f=='>') System.out.println("cw"); else System.out.println("ccw"); break; case '>': if(f=='v') System.out.println("cw"); else System.out.println("ccw"); break; } } else { switch(i) { case 'v': if(f=='>') System.out.println("cw"); else System.out.println("ccw"); break; case '<': if(f=='v') System.out.println("cw"); else System.out.println("ccw"); break; case '^': if(f=='<') System.out.println("cw"); else System.out.println("ccw"); break; case '>': if(f=='^') System.out.println("cw"); else System.out.println("ccw"); break; } } } }
Problem: <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 Solution (in JAVA):
import java.util.Scanner; public class CF834A { public static void main(String[] args) { CF834A task = new CF834A(); Problem solver = task.new Problem(); Scanner in = new Scanner(System.in); solver.initializeStates(); int ans = solver.calculateResult(in.next(), in.next(), in.nextInt()); if(ans == -1) System.out.println("ccw"); else if(ans == 0) System.out.println("undefined"); else if(ans == 1) System.out.println("cw"); } public class Problem { public Problem() { } private char[] states = new char[4]; public void initializeStates() { states[0] = '^'; states[1] = '>'; states[2] = 'v'; states[3] = '<'; } public int calculateResult(String s,String e,int n) { int ans = -1; char crntchr = s.toCharArray()[0]; int sl = getStateIndex(s.toCharArray()[0]); int el = getStateIndex(e.toCharArray()[0]); int rem = n % 4; char clcc; char cntrclc; for(int i = sl + 1, j = 0; j < rem; i++,j++) { if(i > 3) i = 0; crntchr = getState(crntchr, i); } clcc = crntchr; for(int i = sl - 1, j = 0; j < rem; i--,j++) { if(i < 0) i = 3; crntchr = getState(crntchr, i); } cntrclc = crntchr; char cmpchr = e.toCharArray()[0]; if(cmpchr == cntrclc && cntrclc == clcc) ans = 0; else if(cmpchr == clcc) ans = 1; else if(cmpchr == cntrclc) ans = -1; return ans; } private char getState(char crnt,int index) { char ans = '^'; ans = states[index]; return ans; } private int getStateIndex(char crnt) { int ans = -1; for(int i = 0; i < states.length; i++) { if(states[i] == crnt) { ans = i; break; } } return ans; } } }
Problem: <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 Solution (in PYTHON3):
d, s, n = '^>v<', input(), int(input()) if n % 2 == 0: print("undefined") elif (d.find(s[0])+n)%4 == d.find(s[2]): print("cw") else: print("ccw")
Problem: <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 Solution (in PYTHON3):
str1,str2=input().split() #print(str1,str2) n=int(input()) s=['v','<','^','>'] t=n n=n%4 if(n==2 or n==0): print("undefined") else: index1=s.index(str1) index2=s.index(str2) if(index1+n>3): index3=index1+n-4 else: index3=index1+n if(index3==index2): print("cw") else: print("ccw")
Problem: <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 Solution (in JAVA):
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; import javafx.util.Pair; import java.awt.*; import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() throws FileNotFoundException { InputStream inputStream = new FileInputStream("c:/Users/alex/code/HackerRank/JavaCode/input.txt"); br = new BufferedReader(new InputStreamReader(inputStream)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) throws FileNotFoundException { // FastReader in = new FastReader(); Scanner in = new Scanner(System.in); /*Scanner in = null; try { in = new Scanner(new File("c:/Users/alex/code/HackerRank/JavaCode/input.txt")); } catch (FileNotFoundException e) { e.printStackTrace(); }*/ String line=in.nextLine(); String[] strs=line.split(" "); char start=strs[0].charAt(0); char end=strs[1].charAt(0); int stAngle=0; int endAngle=0; if(start=='>'){ stAngle=0; } else if(start=='^'){ stAngle=1; } else if(start=='<'){ stAngle=2; } else if(start=='v'){ stAngle=3; } if(end=='>'){ endAngle=0; } else if(end=='^'){ endAngle=1; } else if(end=='<'){ endAngle=2; } else if(end=='v'){ endAngle=3; } int n=in.nextInt(); n%=4; int endClock=0,endUClock=0; endClock=stAngle+(4-n); endClock%=4; endUClock=stAngle+n; endUClock%=4; if(endClock==endUClock){ System.out.println("undefined"); } else if(endClock==endAngle){ System.out.println("cw"); } else { System.out.println("ccw"); } end=3; } }
Problem: <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 Solution (in PYTHON3):
s,e=input().split() n = int(input()) n %= 4 if(n==2 or n==0): print("undefined") elif(n==1): if((s=='<' and e=='^') or (s=='^' and e=='>') or (s=='>' and e=='v') or (s=='v' and e=='<')): print("cw") else: print("ccw") else: if((s=='<' and e=='v') or (s=='^' and e=='<') or (s=='>' and e=='^') or (s=='v' and e=='>')): print("cw") else: print("ccw")
Problem: <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 Solution (in JAVA):
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.PriorityQueue; import java.util.Random; import java.util.Scanner; import java.io.*; public class Main { public static void main(String[] args) throws FileNotFoundException { // Scanner read = new Scanner(new FileInputStream(new // File("input.txt"))); // PrintWriter out = new PrintWriter(new File("output.txt")); Scanner read = new Scanner(System.in); ArrayList<Character> arr = new ArrayList<Character>(); arr.add('v'); arr.add('<'); arr.add('^'); arr.add('>'); String s = read.next(), z = read.next(); read.nextLine(); int x = arr.indexOf(s.charAt(0)), y = arr.indexOf(z.charAt(0)), n = read.nextInt() % 4; int a = (x + n) % 4 , b = (y + n) % 4 ; if(arr.get(a) == z.charAt(0) && arr.get(b) == s.charAt(0)) System.out.println("undefined"); else if(arr.get(a) == z.charAt(0)) System.out.println("cw"); else System.out.println("ccw"); } }
Problem: <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 Solution (in PYTHON):
a = ["<","^",">","v"] m,n = raw_input().split() c = int(input()) mod = c % 4 start_i = a.index(m) end_i = a.index(n) c_end = (start_i + mod) % 4 cc_end = (start_i - mod + 4) % 4 #print(cc_end,c_end) if mod % 2 == 0: print("undefined") elif cc_end == end_i: print("ccw") else: print("cw")
Problem: <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 Solution (in PYTHON3):
l = 'v<^>' start,end = input().split() s_i = l.index(start) e_i = l.index(end) steps = int(input()) if steps%4 == (s_i-e_i)%4 and steps%4 == (e_i-s_i)%4: print ('undefined') elif steps%4 == (e_i-s_i)%4: print ('cw') elif steps%4 == (s_i-e_i)%4: print ('ccw') else: print ('undefined')
Problem: <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 Solution (in PYTHON3):
a, b = map(str, input().split()) n = int(input()) f1 = ["<", "v", ">", "^"] f2 = ["^", ">", "v", "<"] h = n * 90 % 360 // 90 r = -h j = -h if a == "<": r += 0 j += 3 elif a == "v": r += 1 j += 2 elif a == ">": r += 2 j += 1 else: r += 3 j += 0 if b == f1[r] == f2[j]: print("undefined") elif b == f1[r]: print("cw") elif b == f2[j]: print("ccw") else: print("undefined")
Problem: <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 Solution (in CPP):
#include <bits/stdc++.h> using namespace std; int main() { char s, e; cin >> s >> e; int t; cin >> t; map<char, int> m; m['^'] = 0; m['>'] = 1; m['v'] = 2; m['<'] = 3; t %= 4; if (m[e] == m[s] || abs(m[e] - m[s]) == 2) { cout << "undefined"; } else { if (t == abs(m[e] - m[s]) || t == 4 - abs(m[e] - m[s])) { if (m[e] > m[s]) { if (m[e] - m[s] == t) { cout << "cw"; } else { cout << "ccw"; } } else { if (m[s] - m[e] == t) { cout << "ccw"; } else { cout << "cw"; } } } else { cout << "undefined"; } } return 0; }
Problem: <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 Solution (in PYTHON3):
#!/usr/bin/python3 v1, v2 = input().split() n = int(input()) o1 = ord(v1) o2 = ord(v2) if n % 4 == 0: print("undefined") elif n % 4 == 1: if (o1 == 118 and o2 == 60) or (o1 == 60 and o2 == 94) or (o1 == 94 and o2 == 62) or (o1 == 62 and o2 == 118): print("cw") else: print("ccw") elif n % 4 == 2: print("undefined") else: if (o1 == 118 and o2 == 62) or (o1 == 60 and o2 == 118) or (o1 == 94 and o2 == 60) or (o1 == 62 and o2 == 94): print("cw") else: print("ccw")
Problem: <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 Solution (in PYTHON3):
d = dict(zip('v<^>', range(4))) x, y = input().split() t = int(input()) % 4 print('undefined' if t%2==0 else 'ccw' if t==(d[x]-d[y])%4 else 'cw')
Problem: <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 Solution (in PYTHON3):
li=input().split() n=int(input()) j=n%4 flag=0 anti_clockwise="^<v>^<v>" clockwise="^>v<^>v<" dict1={ "^":"v", "v":"^", ">":"<", "<":">" } if j==0 or li[-1] == dict1[li[0]]: print("undefined") else: k=anti_clockwise.index(li[0]) if anti_clockwise[k+j]==li[-1]: print("ccw") else: print("cw")
Problem: <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 Solution (in PYTHON):
import sys x = sys.stdin.readline().split() y = int(sys.stdin.readline().rstrip("\n")) pos = ["^", ">", "v", "<", "^", ">", "v", "<"] if y % 2 == 0: print("undefined") exit(0) p = y % 4 res1 = pos[pos.index(x[0])+p] res2 = pos[pos.index(x[0])-p] if res1 == x[1]: print("cw") exit(0) if res2 == x[1]: print("ccw")
Problem: <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 Solution (in PYTHON3):
c = ['v', '<', '^', '>'] s, e = list(input().split()) n = int(input()) if n % 2 == 0: print('undefined') si, ei = c.index(s), c.index(e) if n % 4 == 1: if ei - si == 1 or si - ei == 3: print('cw') else: print('ccw') if n % 4 == 3: if ei - si == 1 or si - ei == 3: print('ccw') else: print('cw')
Problem: <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 Solution (in JAVA):
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; import java.lang.*; public class ppm { static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; public InputReader(InputStream st) { this.stream = st; } public int read() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public String readString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } public static void main(String[] args){ InputReader in = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); String s=in.nextLine(); // System.out.println(s); int n=in.nextInt(); char a=s.charAt(0); char b=s.charAt(2); int p=0,q=0; p=n%4; if((a=='v' && b=='<') ) { if(p==1) System.out.println("cw"); else if(p==3) System.out.println("ccw"); else System.out.println("undefined"); } else if((a=='<' && b=='v') ) { if(p==3) System.out.println("cw"); else if(p==1) System.out.println("ccw"); else System.out.println("undefined"); } else if((a=='v' && b=='^') ||(b=='v' && a=='^')) { if(p==2) System.out.println("undefined"); /* else if(p==3) System.out.println("ccw"); else System.out.println("undefined");*/ } else if((a=='v' && b=='>') ) { if(p==3) System.out.println("cw"); else if(p==1) System.out.println("ccw"); else System.out.println("undefined"); } else if((a=='>' && b=='v') ) { if(p==1) System.out.println("cw"); else if(p==3) System.out.println("ccw"); else System.out.println("undefined"); } else if((a=='<' && b=='^')) { if(p==1) System.out.println("cw"); else if(p==3) System.out.println("ccw"); else System.out.println("undefined"); } else if((a=='^' && b=='<')) { if(p==3) System.out.println("cw"); else if(p==1) System.out.println("ccw"); else System.out.println("undefined"); } else if( (a=='<' && b=='>') || (b=='<' && a=='>') ) { if(p==2) System.out.println("undefined"); } else if( (a=='^' && b=='>') ) { if(p==1) System.out.println("cw"); else if(p==3) System.out.println("ccw"); else System.out.println("undefined"); } else if( (a=='>' && b=='^') ) { if(p==3) System.out.println("cw"); else if(p==1) System.out.println("ccw"); else System.out.println("undefined"); } else { System.out.println("undefined"); } } }
Problem: <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 Solution (in JAVA):
import java .util.*; public class St { public static void main(String[]args) { Scanner sc= new Scanner(System.in); String [] s1=(sc.nextLine()).split(" "); //String x1= s1[0]; int x1=(s1[0].equals("v"))?1:(s1[0].equals(">"))?2:(s1[0].equals("<"))?4:3; String x2 =s1[1]; x2=(s1[1].equals("v"))?"1":(s1[1].equals(">"))?"2":(s1[1].equals("<"))?"4":"3"; int s2 =sc.nextInt()%4; if(s2==0&&x1==Integer.parseInt(x2)) { System.out.println("undefined"); } else { if((x1+s2)%4==Integer.parseInt(x2)||(x1+s2)%4+4==Integer.parseInt(x2)) { if(x1-s2<=0) { if(x1-s2+4==Integer.parseInt(x2)) { System.out.println("undefined"); } else System.out.println("ccw"); } else { if(x1-s2==Integer.parseInt(x2)) { System.out.println("undefined"); } else System.out.println("ccw"); } } else { if(x1-s2<=0) { if(x1-s2+4==Integer.parseInt(x2)) { System.out.println("cw"); } } else { if(x1-s2==Integer.parseInt(x2)) { System.out.println("cw"); } else { System.out.println("undefined"); } } } } } }
Problem: <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 Solution (in CPP):
#include <bits/stdc++.h> char c[5] = {'^', '>', 'v', '<'}; int main() { char a, b; int d, x, y, z; scanf("%c %c", &a, &b); scanf("%d", &z); for (int i = 0; i < 4; i++) { if (c[i] == a) d = i; } x = (z + d) % 4; y = ((d - z) % 4 + 4) % 4; if (x == y) printf("undefined"); else if (c[x] == b) printf("cw"); else printf("ccw"); return 0; }
Problem: <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 Solution (in CPP):
#include <bits/stdc++.h> using namespace std; bool check(char a, char b, string s, int k) { int p = 0; for (int i = 0; i < 4; ++i) if (a == s[i]) p = i; return s[(p + k) % 4] == b; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); string s = "v<^>"; char a, b; cin >> a >> b; int n; cin >> n; n %= 4; bool cw = check(a, b, s, n); bool ccw = check(b, a, s, n); if (cw && ccw) cout << "undefined" << endl; else if (cw) cout << "cw" << endl; else cout << "ccw" << endl; }
Problem: <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 Solution (in JAVA):
import java.util.Scanner; public class P834A { static String pos = "v<^>"; static String rev = ">^<v"; public static void main(String[] args) { Scanner scan = new Scanner(System.in); char a = scan.next().charAt(0); char b = scan.next().charAt(0); int n = scan.nextInt()%4; int pa = pos.indexOf(a); int pb = pos.indexOf(b); int diff1 = (pb-n+16-pa)%4; int diff2 = (rev.indexOf(b)-n+16-rev.indexOf(a))%4; if (diff1 == 0 && diff2 == 0) System.out.println("undefined"); else if (diff1 == 0) System.out.println("cw"); else if (diff2 == 0) System.out.println("ccw"); else System.out.println("undefined"); } }
Problem: <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 Solution (in PYTHON3):
directions = ['v', '<', '^', '>'] x, y = map(directions.index, input().split()) n = int(input()) a = (y - x + 4) % 4 if a == 0 or a == 2: print('undefined') elif a == n % 4: print('cw') else: print('ccw')
Problem: <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 Solution (in CPP):
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); ; char a, b; cin >> a >> b; long long n; cin >> n; n = n % 4; long long p, q; if (a == '^') { p = 0; } else if (a == '>') { p = 1; } else if (a == 'v') { p = 2; } else if (a == '<') { p = 3; } if (b == '^') { q = 0; } else if (b == '>') { q = 1; } else if (b == 'v') { q = 2; } else if (b == '<') { q = 3; } int k = (q - p) % 4; if (k < 0) { k += 4; } if (n == 2 || n == 0) { cout << "undefined"; } else if (n == k) { cout << "cw"; } else if (n == 4 - k) { cout << "ccw"; } return 0; }
Problem: <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 Solution (in PYTHON3):
cw = {"v": 0, "<": 1, "^": 2, ">": 3} ccw = {"v": 0, ">": 1, "^": 2, "<": 3} s, e = input().split() n = int(input()) n = n % 4 if n == 0: print("undefined") else: if (cw[s] + n) % 4 == cw[e] and (ccw[s] + n) % 4 != ccw[e]: print("cw") elif (cw[s] + n) % 4 != cw[e] and (ccw[s] + n) % 4 == ccw[e]: print("ccw") else: print("undefined")
Problem: <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 Solution (in JAVA):
import java.io.*; import java.util.*; public class Main { private InputStream is; private PrintWriter out; int time = 0, val[][], dp[][], DP[], start[], end[], dist[], black[], MOD = (int)(1e9+7), arr[], weight[][], x[], y[], parent[]; int MAX = 800000, N, K; long red[]; ArrayList<Integer>[] amp; ArrayList<Pair>[][] pmp; boolean b[], boo[][]; Pair prr[]; HashMap<Integer,Long> hm[] = new HashMap[305]; long Dp[][][][] = new long[110][110][12][12]; void soln() { is = System.in; out = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); //out.close(); out.flush(); //tr(System.currentTimeMillis() - s + "ms"); } public static void main(String[] args) throws Exception { new Thread(null, new Runnable() { public void run() { try { //new CODEFORCES().soln(); } catch (Exception e) { System.out.println(e); } } }, "1", 1 << 26).start(); new Main().soln(); } int ans = 0, cost = 0; char ch[], ch1[]; void solve(){ char ch1 = ns().charAt(0), ch2 = ns().charAt(0); int n = ni(); int y = n%4; if(y==0 || y==2){ System.out.println("undefined"); return; } else if(y==1){ if(ch1=='^'){ if(ch2=='>'){ System.out.println("cw"); } else if(ch2=='<') System.out.println("ccw"); else System.out.println("undefined"); return; } else if(ch1=='>'){ if(ch2=='v'){ System.out.println("cw"); } else if(ch2=='^') System.out.println("ccw"); else System.out.println("undefined"); return; } else if(ch1=='<'){ if(ch2=='^'){ System.out.println("cw"); } else if(ch2=='v') System.out.println("ccw"); else System.out.println("undefined"); return; } else if(ch1=='v'){ if(ch2=='<'){ System.out.println("cw"); } else if(ch2=='>') System.out.println("ccw"); else System.out.println("undefined"); return; } } else{ if(ch1=='^'){ if(ch2=='<'){ System.out.println("cw"); } else if(ch2=='>') System.out.println("ccw"); else System.out.println("undefined"); return; } else if(ch1=='>'){ if(ch2=='^'){ System.out.println("cw"); } else if(ch2=='v') System.out.println("ccw"); else System.out.println("undefined"); return; } else if(ch1=='<'){ if(ch2=='v'){ System.out.println("cw"); } else if(ch2=='^') System.out.println("ccw"); else System.out.println("undefined"); return; } else if(ch1=='v'){ if(ch2=='>'){ System.out.println("cw"); } else if(ch2=='<') System.out.println("ccw"); else System.out.println("undefined"); return; } } } void sieve(int n){ b = new boolean[n+1]; b[0] = b[1] = true; for(int i = 2;i*i<n;i++){ if(!b[i]){ for(int j = 2*i;j<100001;j+=i) b[j] = true; } } } class Pair implements Comparable<Pair>{ int u, v, i; Pair(int u, int v){ this.u = u; this.v = v; } Pair(){ } Pair(int u, int v, int i){ this.u = u; this.v = v; this.i = i; } public int hashCode() { return Objects.hash(); } public boolean equals(Object o) { Pair other = (Pair) o; return ((u == other.u && v == other.v)); } public int compareTo(Pair other) { //return Integer.compare(val, other.val); return Long.compare(u, other.u) != 0 ? (Long.compare(u, other.u)) : (Long.compare(v,other.v)); } public String toString(){ return this.u +" " + this.v; } } int max(int a, int b){ if(a>b) return a; return b; } public static class FenwickTree { int[] array; // 1-indexed array, In this array We save cumulative information to perform efficient range queries and updates public FenwickTree(int size) { array = new int[size + 1]; } public int rsq(int ind) { assert ind > 0; int sum = 0; while (ind > 0) { sum += array[ind]; //Extracting the portion up to the first significant one of the binary representation of 'ind' and decrementing ind by that number ind -= ind & (-ind); } return sum; } public int rsq(int a, int b) { assert b >= a && a > 0 && b > 0; return rsq(b) - rsq(a - 1); } public void update(int ind, int value) { assert ind > 0; while (ind < array.length) { array[ind] += value; //Extracting the portion up to the first significant one of the binary representation of 'ind' and incrementing ind by that number ind += ind & (-ind); } } public int size() { return array.length - 1; } } void buildGraph(int n){ for(int i = 0; i<n ;i++){ int x1 = ni() -1, y1 = ni()-1; amp[x1].add(y1); amp[y1].add(x1); x[i] = x1; y[i] = y1; } } long modInverse(long a, long mOD2){ return power(a, mOD2-2, mOD2); } long power(long x, long y, long m) { if (y == 0) return 1; long p = power(x, y/2, m) % m; p = (p * p) % m; return (y%2 == 0)? p : (x * p) % m; } public int gcd(int a, int b){ if(b==0) return a; return gcd(b,a%b); } static class ST1{ int arr[], st[], size; ST1(int a[]){ arr = a.clone(); size = 10*arr.length; st = new int[size]; build(0,arr.length-1,1); } void build(int ss, int se, int si){ if(ss==se){ st[si] = arr[ss]; return; } int mid = (ss+se)/2; int val = 2*si; build(ss,mid,val); build(mid+1,se,val+1); st[si] = Math.min(st[val], st[val+1]); } int get(int ss, int se, int l, int r, int si){ if(l>se || r<ss || l>r) return Integer.MAX_VALUE; if(l<=ss && r>=se) return st[si]; int mid = (ss+se)/2; int val = 2*si; return Math.min(get(ss,mid,l,r,val), get(mid+1,se,l,r,val+1)); } } static class ST{ int arr[],lazy[],n; ST(int a){ n = a; arr = new int[10*n]; lazy = new int[10*n]; } void up(int l,int r,int val){ update(0,n-1,0,l,r,val); } void update(int l,int r,int c,int x,int y,int val){ if(lazy[c]!=0){ lazy[2*c+1]+=lazy[c]; lazy[2*c+2]+=lazy[c]; if(l==r) arr[c]+=lazy[c]; lazy[c] = 0; } if(l>r||x>y||l>y||x>r) return; if(x<=l&&y>=r){ lazy[c]+=val; return ; } int mid = l+r>>1; update(l,mid,2*c+1,x,y,val); update(mid+1,r,2*c+2,x,y,val); arr[c] = Math.max(arr[2*c+1], arr[2*c+2]); } int an(int ind){ return ans(0,n-1,0,ind); } int ans(int l,int r,int c,int ind){ if(lazy[c]!=0){ lazy[2*c+1]+=lazy[c]; lazy[2*c+2]+=lazy[c]; if(l==r) arr[c]+=lazy[c]; lazy[c] = 0; } if(l==r) return arr[c]; int mid = l+r>>1; if(mid>=ind) return ans(l,mid,2*c+1,ind); return ans(mid+1,r,2*c+2,ind); } } public static int[] shuffle(int[] a, Random gen){ for(int i = 0, n = a.length;i < n;i++) { int ind = gen.nextInt(n-i)+i; int d = a[i]; a[i] = a[ind]; a[ind] = d; } return a; } long power(long x, long y, int mod){ long ans = 1; while(y>0){ if(y%2==0){ x = (x*x)%mod; y/=2; } else{ ans = (x*ans)%mod; y--; } } return ans; } // To Get Input // Some Buffer Methods private byte[] inbuf = new byte[1024]; public int lenbuf = 0, ptrbuf = 0; private int readByte() { if (lenbuf == -1) throw new InputMismatchException(); if (ptrbuf >= lenbuf) { ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) return -1; } return inbuf[ptrbuf++]; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) ; return b; } private double nd() { return Double.parseDouble(ns()); } private char nc() { return (char) skip(); } private String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' // ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while (p < n && !(isSpaceChar(b))) { buf[p++] = (char) b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private char[][] nm(int n, int m) { char[][] map = new char[n][]; for (int i = 0; i < n; i++) map[i] = ns(m); return map; } private int[] na(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = ni(); return a; } private int ni() { int num = 0, b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } private long nl() { long num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } private boolean oj = System.getProperty("ONLINE_JUDGE") != null; private void tr(Object... o) { if (!oj) System.out.println(Arrays.deepToString(o)); } }
Problem: <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 Solution (in CPP):
#include <bits/stdc++.h> using namespace std; long long const delta = 1000000007; int main() { std::ios::sync_with_stdio(0); ; cin.tie(0); cout.tie(0); char a, b; cin >> a >> b; long long t; cin >> t; long long a1, b1; if (a == '^') a1 = 0; if (a == '>') a1 = 1; if (a == 'v') a1 = 2; if (a == '<') a1 = 3; if (b == '^') b1 = 0; if (b == '>') b1 = 1; if (b == 'v') b1 = 2; if (b == '<') b1 = 3; if (((a1 + t) % 4 == b1) && ((a1 - t + (4 * (long long)1e12 + 8)) % 4 == b1)) return cout << "undefined", 0; if ((a1 + t) % 4 == b1) return cout << "cw", 0; if ((a1 - t + (4 * (long long)1e12 + 8)) % 4 == b1) return cout << "ccw", 0; cout << "undefined "; return 0; }
Problem: <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 Solution (in PYTHON3):
def rotate(start, n_rotations, direction): return (start + (n_rotations * direction)) % 4 def main(): positions = {'^': 0, '>': 1, 'v': 2, '<': 3} [start, end] = input().split() (start, end) = (positions[start], positions[end]) n_rotations = int(input()) clockwise = rotate(start, n_rotations, 1) cclockwise = rotate(start, n_rotations, -1) print('undefined' if clockwise == cclockwise else 'cw' if clockwise == end else 'ccw') if __name__ == '__main__': main()
Problem: <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 Solution (in JAVA):
import java.util.*; public class A { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String s=sc.nextLine(); char N=s.charAt(0); char M=s.charAt(2); int X=Integer.parseInt(sc.nextLine()); int K=0; int J=0; if (N==118){ K=0; } if (N==60){ K=1; } if (N==94){ K=2; } if (N==62){ K=3; } if (M==118){ J=0; } if (M==60){ J=1; } if (M==94){ J=2; } if (M==62){ J=3; } if (X%4==(J-K+8)%4 && X%4!=(K-J+8)%4){ System.out.println("cw"); } else if(X%4==(K-J+8)%4 && X%4!=(J-K+8)%4){ System.out.println("ccw"); } else{ System.out.println("undefined"); } } }
Problem: <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 Solution (in JAVA):
import java.io.*; import java.math.*; import java.util.*; import java.util.stream.*; @SuppressWarnings("unchecked") public class P834A { public void run() throws Exception { Map<Character, char []> cw = new HashMap(), ccw = new HashMap(); cw.put('^', new char [] { '^', '>', 'v', '<' }); cw.put('>', new char [] { '>', 'v', '<', '^' }); cw.put('v', new char [] { 'v', '<', '^', '>' }); cw.put('<', new char [] { '<', '^', '>', 'v' }); ccw.put('^', new char [] { '^', '<', 'v', '>' }); ccw.put('<', new char [] { '<', 'v', '>', '^' }); ccw.put('v', new char [] { 'v', '>', '^', '<' }); ccw.put('>', new char [] { '>', '^', '<', 'v' }); char s = next().charAt(0), f = next().charAt(0); int r = nextInt() & 0b11; char fcw = cw.get(s)[r], fccw = ccw.get(s)[r]; if ((fcw == f) && (fccw != f)) { println("cw"); } else if ((fcw != f) && (fccw == f)) { println("ccw"); } else { println("undefined"); } } public static void main(String... args) throws Exception { br = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(new BufferedOutputStream(System.out)); new P834A().run(); br.close(); pw.close(); System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]"); } static long startTime = System.currentTimeMillis(); static BufferedReader br; static PrintWriter pw; StringTokenizer stok; String nextToken() throws IOException { while (stok == null || !stok.hasMoreTokens()) { String s = br.readLine(); if (s == null) { return null; } stok = new StringTokenizer(s); } return stok.nextToken(); } void print(byte b) { print("" + b); } void print(int i) { print("" + i); } void print(long l) { print("" + l); } void print(double d) { print("" + d); } void print(char c) { print("" + c); } void print(Object o) { if (o instanceof int[]) { print(Arrays.toString((int [])o)); } else if (o instanceof long[]) { print(Arrays.toString((long [])o)); } else if (o instanceof char[]) { print(Arrays.toString((char [])o)); } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o)); } else if (o instanceof short[]) { print(Arrays.toString((short [])o)); } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o)); } else if (o instanceof float[]) { print(Arrays.toString((float [])o)); } else if (o instanceof double[]) { print(Arrays.toString((double [])o)); } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o)); } else { print("" + o); } } void print(String s) { pw.print(s); } void println() { println(""); } void println(byte b) { println("" + b); } void println(int i) { println("" + i); } void println(long l) { println("" + l); } void println(double d) { println("" + d); } void println(char c) { println("" + c); } void println(Object o) { print(o); println(); } void println(String s) { pw.println(s); } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } char nextChar() throws IOException { return (char) (br.read()); } String next() throws IOException { return nextToken(); } String nextLine() throws IOException { return br.readLine(); } int [] readInt(int size) throws IOException { int [] array = new int [size]; for (int i = 0; i < size; i++) { array[i] = nextInt(); } return array; } long [] readLong(int size) throws IOException { long [] array = new long [size]; for (int i = 0; i < size; i++) { array[i] = nextLong(); } return array; } double [] readDouble(int size) throws IOException { double [] array = new double [size]; for (int i = 0; i < size; i++) { array[i] = nextDouble(); } return array; } String [] readLines(int size) throws IOException { String [] array = new String [size]; for (int i = 0; i < size; i++) { array[i] = nextLine(); } return array; } int gcd(int a, int b) { if (a == 0) return Math.abs(b); if (b == 0) return Math.abs(a); a = Math.abs(a); b = Math.abs(b); int az = Integer.numberOfTrailingZeros(a), bz = Integer.numberOfTrailingZeros(b); a >>>= az; b >>>= bz; while (a != b) { if (a > b) { a -= b; a >>>= Integer.numberOfTrailingZeros(a); } else { b -= a; b >>>= Integer.numberOfTrailingZeros(b); } } return (a << Math.min(az, bz)); } long gcd(long a, long b) { if (a == 0) return Math.abs(b); if (b == 0) return Math.abs(a); a = Math.abs(a); b = Math.abs(b); int az = Long.numberOfTrailingZeros(a), bz = Long.numberOfTrailingZeros(b); a >>>= az; b >>>= bz; while (a != b) { if (a > b) { a -= b; a >>>= Long.numberOfTrailingZeros(a); } else { b -= a; b >>>= Long.numberOfTrailingZeros(b); } } return (a << Math.min(az, bz)); } }
Problem: <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 Solution (in PYTHON3):
s=input() n=int(input()) a="v<^>v<^>" b="v>^<v>^<" if n%2==0:print("undefined") elif a[a.index(s[0])+(n%4)]==s[2]:print("cw") elif b[b.index(s[0])+(n%4)]==s[2]:print("ccw")
Problem: <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 Solution (in CPP):
#include <bits/stdc++.h> using namespace std; int main() { int n; int pol; int konpol; int sekund; char k1, s1; cin >> s1 >> k1 >> sekund; switch (s1) { case 118: pol = 0; break; case 60: pol = 1; break; case 94: pol = 2; break; case 62: pol = 3; break; } switch (k1) { case 118: konpol = 0; break; case 60: konpol = 1; break; case 94: konpol = 2; break; case 62: konpol = 3; break; } int pol1 = pol; int pol2 = pol; pol1 = (pol1 + sekund) % 4; pol2 = (pol2 - sekund) % 4; if (pol2 == -1) pol2 = 3; if (pol2 == -3) pol2 = 1; pol2 = abs(pol2); if (pol2 == konpol && pol1 == konpol) { cout << "undefined"; } else if (pol1 == konpol) { cout << "cw"; } else if (pol2 == konpol) cout << "ccw"; else cout << "undefined"; return 0; }
Problem: <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 Solution (in JAVA):
import java.util.*; public class Main { public static void main(String args[]) { Scanner sc=new Scanner(System.in); String s=sc.next(); int st=(int)s.charAt(0); s=sc.next(); int en=(int)s.charAt(0); int n=sc.nextInt(); n=n%4; int cw[]={118,60,94,62}; int ccw[]={118,62,94,60}; int cw_pos=0; int ccw_pos=0; for(int i=0;i<4;i++) { if(cw[i]==st) cw_pos=i; if(ccw[i]==st) ccw_pos=i; } cw_pos=(cw_pos+n)%4; ccw_pos=(ccw_pos+n)%4; String ans=""; if(cw[cw_pos]==en) ans="cw"; if(ccw[ccw_pos]==en) ans="ccw"; if(cw[cw_pos]==en&&ccw[ccw_pos]==en) ans="undefined"; if(cw[cw_pos]!=en&&ccw[ccw_pos]!=en) ans="undefined"; System.out.println(ans); } }
Problem: <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 Solution (in PYTHON):
c1, c2 = raw_input().split() N = int(raw_input()) N = N % 4 d = {} d["^"] = 0 d[">"] = 1 d["v"] = 2 d["<"] = 3 di = {} di[0] = "^" di[1] = ">" di[2] = "v" di[3] = "<" if di[(d[c1]+N) % 4] == c2 and di[(d[c1]-N) % 4] != c2: print "cw" elif di[(d[c1]-N) % 4] == c2 and di[(d[c1]+N) % 4] != c2: print "ccw" else: print "undefined"
Problem: <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 Solution (in PYTHON3):
elem = ['v', '<', '^', '>'] a, b = map(elem.index, input().split()) n = int(input()) diff = (b - a + 4) % 4 if (diff == 0 or diff == 2): print('undefined') elif (diff == n % 4): print('cw') else: print('ccw')
Problem: <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 Solution (in PYTHON):
a,b = raw_input().split() n = input() d = {'v':1, '<':2, '^':3, '>':4} cw, ccw = (d[b]-d[a])%4 == n%4, (d[a]-d[b])%4 == n%4 if cw and ccw: print "undefined" elif cw: print "cw" elif ccw: print "ccw" else: print "undefined"
Problem: <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 Solution (in PYTHON3):
s = input().split() num = int(input()) % 4 if s[0] == s[1] or s[0] == "^" and s[1] == "v" or s[0] == "v" and s[1] == "^" or s[0] == "<" and s[1] == ">" or s[0] == ">" and s[1] == "<": print("undefined") else: mapping = ["v", "<", "^", ">", "v", "<", "^", ">"] if num == 1: ind1 = mapping.index(s[0]) ind2 = mapping[ind1:].index(s[1]) if 1 == ind2: print("cw") else: print("ccw") # print(ind1) # print(ind2) else: ind1 = mapping.index(s[0]) ind2 = mapping[ind1:].index(s[1]) if 3 == ind2: print("cw") else: print("ccw")
Problem: <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 Solution (in PYTHON3):
start, end = input().split(' ') n = int(input()) xn = n yn = n if start == '^': xn += 0 elif start == '>': xn += 1 elif start == 'v': xn += 2 elif start == '<': xn += 3 if start == '^': yn += 0 elif start == '<': yn += 1 elif start == 'v': yn += 2 elif start == '>': yn += 3 states_cw = "^>v<" states_ccw = "^<v>" xn %= 4 yn %= 4 if states_cw[xn] == end and states_ccw[yn] == end: print("undefined") elif states_cw[xn] == end: print("cw") elif states_ccw[yn] == end: print("ccw") else: print("undefined")
Problem: <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 Solution (in PYTHON):
import sys lookup = {'^': 0, '>': 1, 'v': 2, '<': 3} def solve(dir_a, dir_b, dur): if (lookup[dir_a] - lookup[dir_b]) % 2 == 0: return "undefined" else: final_cand = (lookup[dir_a] + dur) % 4 other_cand = ((lookup[dir_a] - dur) + (4*dur)) % 4 if final_cand == lookup[dir_b]: return "cw" elif other_cand == lookup[dir_b]: return "ccw" else: return "undefined" if __name__ == "__main__": dir_a, dir_b = sys.stdin.readline().strip().split() dur = int(sys.stdin.readline()) print solve(dir_a, dir_b, dur)
Problem: <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 Solution (in PYTHON3):
import sys a,b=input().split() n=int(input()) if a=='v': lcw=['<','^','>','v'] lccw=['>','^','<','v'] n=n%4-1 if lcw[n]==lccw[n]: print("undefined") sys.exit() elif lcw[n]==b: print("cw") sys.exit() elif lccw[n]==b: print("ccw") elif a=='^': lcw=['>','v','<','^'] lccw=['<','v','>','^',] n=n%4-1 if lcw[n]==lccw[n]: print("undefined") sys.exit() elif lcw[n]==b: print("cw") sys.exit() elif lccw[n]==b: print("ccw") elif a=='>': lcw=['v','<','^','>'] lccw=['^','<','v','>'] n=n%4-1 if lcw[n]==lccw[n]: print("undefined") sys.exit() elif lcw[n]==b: print("cw") sys.exit() elif lccw[n]==b: print("ccw") elif a=='<': lcw=['^','>','v','<'] lccw=['v','>','^','<'] n=n%4-1 if lcw[n]==lccw[n]: print("undefined") sys.exit() elif lcw[n]==b: print("cw") sys.exit() elif lccw[n]==b: print("ccw")