Search is not available for this dataset
name
stringlengths 2
112
| description
stringlengths 29
13k
| source
int64 1
7
| difficulty
int64 0
25
| solution
stringlengths 7
983k
| language
stringclasses 4
values |
---|---|---|---|---|---|
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
long long modpow(long long a, long long n) {
long long ret = 1;
long long b = a;
while (n) {
if (n & 1) ret = (ret * b) % 1000000007ll;
b = (b * b) % 1000000007ll;
n >>= 1;
}
return (long long)ret;
}
string tmp = "^>v<";
int main() {
char g[2];
cin >> g[0] >> g[1];
int x = (tmp.find(g[1]) - tmp.find(g[0]) + 4) % 4;
int n;
cin >> n;
if (n % 4 == 2 or n % 4 == 0)
puts("undefined");
else if (n % 4 == x)
puts("cw");
else
puts("ccw");
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int a[128], p, q, p0, q0, s;
char pc, qc;
bool cw, ccw;
int main() {
a['v'] = 0, a['<'] = 1, a['^'] = 2, a['>'] = 3;
cin >> pc >> qc >> s;
p0 = a[pc], q0 = a[qc], s %= 4;
if ((p0 + s) % 4 == q0) cw = true;
if ((p0 + 3 * s) % 4 == q0) ccw = true;
if (cw && ccw)
cout << "undefined";
else if (cw)
cout << "cw";
else
cout << "ccw";
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const double PI = acos(-1.0);
long long f[555], n;
string g[] = {"<", "^", ">", "v"};
string s, t;
int main() {
cin >> s >> t;
cin >> n;
if (n % 2 == 0) {
cout << "undefined";
return 0;
}
for (int i = 0; i < 4; i++)
if (s == g[i]) {
if (g[(i + (n % 4)) % 4] == t)
cout << "cw";
else
cout << "ccw";
}
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static void main(String[] args) {
MyScanner sc = new MyScanner();
List<Character> rows = new ArrayList<>(4);
rows.add('v');
rows.add('<');
rows.add('^');
rows.add('>');
String str1 = sc.next();
String str2 = sc.next();
int first = rows.indexOf(str1.charAt(0));
int last = rows.indexOf(str2.charAt(0));
int n = sc.nextInt() % 4;
if(n == 0 || n == 2){
System.out.println("undefined");
return;
}
if(n == 1){
if(rows.get((first+1)%4) == rows.get(last)){
System.out.println("cw");
} else {
System.out.println("ccw");
}
}
if(n == 3){
if(rows.get((first+3)%4) == rows.get(last)){
System.out.println("cw");
} else {
System.out.println("ccw");
}
}
}
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 0x7ffffff;
const int magic = 348;
string s1, s2;
string s;
int n;
int nxt1[200], nxt2[200];
int main() {
cin >> s1 >> s2;
cin >> n;
n %= 4;
nxt1[94] = 62;
nxt1[62] = 118;
nxt1[118] = 60;
nxt1[60] = 94;
nxt2[94] = 60;
nxt2[60] = 118;
nxt2[118] = 62;
nxt2[62] = 94;
bool f1 = false, f2 = false;
s = s1;
for (int i = 1; i <= n; i++) s[0] = nxt1[s[0]];
if (s == s2) f1 = true;
s = s1;
for (int i = 1; i <= n; i++) s[0] = nxt2[s[0]];
if (s == s2) f2 = true;
if (f1 && f2) {
cout << "undefined" << endl;
} else {
if (f1)
cout << "cw" << endl;
else
cout << "ccw" << endl;
}
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | start_end = input().strip()
time = int(input().strip())
start = start_end.split()[0]
end = start_end.split()[1]
start_dir = -1
end_dir = -1
if start == '<':
start_dir = 0
elif start == '^':
start_dir = 1
elif start == '>':
start_dir = 2
elif start == 'v':
start_dir = 3
if end == '<':
end_dir = 0
elif end == '^':
end_dir = 1
elif end == '>':
end_dir = 2
elif end == 'v':
end_dir = 3
turns = time
ccw =False
cw = False
if (start_dir == end_dir) or (start_dir % 2 == end_dir %2):
print('undefined')
elif (start_dir + turns) % 4 == end_dir:
print('cw')
else:
print('ccw')
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.util.*;
public class ProblemA {
public static void main(String[] argc)
{
Scanner sc = new Scanner(System.in);
int start_pos, end_pos;
int n;
start_pos = (int)sc.next().charAt(0);
end_pos = (int)sc.next().charAt(0);
n = sc.nextInt();
int real_n = n % 4;
int arrow_down = 118;
int arrow_left = 60;
int arrow_up = 94;
int arrow_right = 62;
boolean cw_dir = false;
boolean ccw_dir = false;
// Try clockwise
if(start_pos == arrow_down)
{
if(real_n == 1)
{
if(end_pos == arrow_left)
{
cw_dir = true;
}
}
if(real_n == 2)
{
if(end_pos == arrow_up)
{
cw_dir = true;
}
}
if(real_n == 3)
{
if(end_pos == arrow_right)
{
cw_dir = true;
}
}
}
if(start_pos == arrow_left)
{
if(real_n == 1)
{
if(end_pos == arrow_up)
{
cw_dir = true;
}
}
if(real_n == 2)
{
if(end_pos == arrow_right)
{
cw_dir = true;
}
}
if(real_n == 3)
{
if(end_pos == arrow_down)
{
cw_dir = true;
}
}
}
if(start_pos == arrow_up)
{
if(real_n == 1)
{
if(end_pos == arrow_right)
{
cw_dir = true;
}
}
if(real_n == 2)
{
if(end_pos == arrow_down)
{
cw_dir = true;
}
}
if(real_n == 3)
{
if(end_pos == arrow_left)
{
cw_dir = true;
}
}
}
if(start_pos == arrow_right)
{
if(real_n == 1)
{
if(end_pos == arrow_down)
{
cw_dir = true;
}
}
if(real_n == 2)
{
if(end_pos == arrow_left)
{
cw_dir = true;
}
}
if(real_n == 3)
{
if(end_pos == arrow_up)
{
cw_dir = true;
}
}
}
// Try counter-clockwise
if(start_pos == arrow_down)
{
if(real_n == 1)
{
if(end_pos == arrow_right)
{
ccw_dir = true;
}
}
if(real_n == 2)
{
if(end_pos == arrow_up)
{
ccw_dir = true;
}
}
if(real_n == 3)
{
if(end_pos == arrow_left)
{
ccw_dir = true;
}
}
}
if(start_pos == arrow_left)
{
if(real_n == 1)
{
if(end_pos == arrow_down)
{
ccw_dir = true;
}
}
if(real_n == 2)
{
if(end_pos == arrow_right)
{
ccw_dir = true;
}
}
if(real_n == 3)
{
if(end_pos == arrow_up)
{
ccw_dir = true;
}
}
}
if(start_pos == arrow_up)
{
if(real_n == 1)
{
if(end_pos == arrow_left)
{
ccw_dir = true;
}
}
if(real_n == 2)
{
if(end_pos == arrow_down)
{
ccw_dir = true;
}
}
if(real_n == 3)
{
if(end_pos == arrow_right)
{
ccw_dir = true;
}
}
}
if(start_pos == arrow_right)
{
if(real_n == 1)
{
if(end_pos == arrow_up)
{
ccw_dir = true;
}
}
if(real_n == 2)
{
if(end_pos == arrow_left)
{
ccw_dir = true;
}
}
if(real_n == 3)
{
if(end_pos == arrow_down)
{
ccw_dir = true;
}
}
}
if(cw_dir == true && ccw_dir == false)
System.out.println("cw");
if(cw_dir == false && ccw_dir == true)
System.out.println("ccw");
if(cw_dir == true && ccw_dir == true)
System.out.println("undefined");
if(cw_dir == false && ccw_dir == false)
System.out.println("undefined");
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | S = list(input().split())
order = ['^', '>', 'v', '<']
N = int(input()) % 4
if N == 2 or N == 0:
print("undefined")
elif N == 1:
if order.index(S[1]) - order.index(S[0]) == 1 or order.index(S[1]) - order.index(S[0]) == -3:
print("cw")
else:
print("ccw")
elif N == 3:
if order.index(S[1]) - order.index(S[0]) == 3 or order.index(S[1]) - order.index(S[0]) == -1:
print("cw")
else:
print("ccw")
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
inline long long getint() {
long long _x = 0, _tmp = 1;
char _tc = getchar();
while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
if (_tc == '-') _tc = getchar(), _tmp = -1;
while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_tc - '0'), _tc = getchar();
return _x * _tmp;
}
bool _cmp(const pair<int, int>& i, const pair<int, int>& j) {
return ((i.first == j.first) ? (i.second > j.second) : (i.first < j.first));
}
struct Node {
int x, y;
Node(int a = 0, int b = 0) : x(a), y(b) {}
bool operator<(const Node& a) const {
return ((x == a.x) ? (y > a.y) : (x < a.x));
}
};
const int mxn = 1e0 + 1;
double eps = 1e-9;
long long ncase = 1;
long long N, M, a, b, c;
string in1, in2;
map<char, int> mp;
int st, en;
void pre() { return; }
void init() {
mp['v'] = 0;
mp['<'] = 1;
mp['^'] = 2;
mp['>'] = 3;
cin >> in1 >> in2 >> N;
st = mp[in1[0]];
en = mp[in2[0]];
}
void sol() {
N %= 4;
if ((st + N) % 4 == en && (st + 4 - N) % 4 == en)
puts("undefined");
else if ((st + N) % 4 == en)
puts("cw");
else if ((st + 4 - N) % 4 == en)
puts("ccw");
else
puts("undefined");
return;
}
int main() {
pre();
while (ncase--) {
init();
sol();
}
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | s = input()
n = int(input())
if not(n%2):
print("undefined")
elif ("^>v<".find(s[0])+n)%4 == "^>v<".find(s[2]):
print("cw")
else:
print("ccw")
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | a=input()
a=a.split()
b=a[1]
a=a[0]
n=int(input())
d=['v','<','^','>']
z=d.index(a)+1-1
c=d.index(b)+1-1
h=n%4
u=d[z-h]
result=[]
if u==d[c]:
result.append('ccw')
p=d[(h+z)%4]
if p==d[c]:
result.append('cw')
if len(result)!=1:
print('undefined')
else:
print(result[0])
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int ha(char ch) {
if (ch == '>') {
return 4;
} else if (ch == 'v') {
return 1;
} else if (ch == '<') {
return 2;
} else if (ch == '^') {
return 3;
} else
return 0;
}
int main() {
char ch1, ch2;
int a1, a2, n;
cin >> ch1 >> ch2 >> n;
n %= 4;
a1 = ha(ch1);
a2 = ha(ch2);
int temp = (a2 - a1 + 4) % 4;
if (temp == 2 || temp == 0) {
cout << "undefined";
} else if (temp == n) {
cout << "cw";
} else if (temp = 4 - n) {
cout << "ccw";
} else
cout << "undefined";
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | cw = ['v','<','^','>']
ccw = ['v','>','^','<']
s,e = raw_input().split()
n = input()
n = n%4
icw, iccw = cw.index(s), ccw.index(s)
ecw, eccw = cw[(icw+n)%4], ccw[(iccw+n)%4]
if ecw == e and eccw == e:
print "undefined"
elif eccw == e:
print "ccw"
elif ecw == e:
print "cw"
else:
print "undefined" | PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author yittg
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
static class TaskA {
private String spin(String c, boolean cw) {
switch (c) {
case "v":
return cw ? "<" : ">";
case "<":
return cw ? "^" : "v";
case "^":
return cw ? ">" : "<";
case ">":
return cw ? "v" : "^";
}
return null;
}
public void solve(int testNumber, Scanner in, PrintWriter out) {
String sta = in.next();
String end = in.next();
int n = in.nextInt() % 4;
String cw = sta;
String ccw = sta;
while (n-- > 0) {
cw = spin(cw, true);
ccw = spin(ccw, false);
}
if (end.equals(cw) && end.equals(ccw)) {
out.println("undefined");
} else if (!end.equals(cw) && !end.equals(ccw)) {
out.println("undefined");
} else {
out.println(end.equals(cw) ? "cw" : "ccw");
}
}
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
/**
* @author Don Li
*/
public class TheUselessToy {
String P = "v<^>";
void solve() {
char a = in.nextToken().charAt(0), b = in.nextToken().charAt(0);
int n = in.nextInt();
n &= 3;
if (n == 0 || n == 2) {
out.println("undefined");
return;
}
int p = P.indexOf(a), q = P.indexOf(b);
if (((p + n) & 3) == q) out.println("cw");
else out.println("ccw");
}
public static void main(String[] args) {
in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
out = new PrintWriter(System.out);
new TheUselessToy().solve();
out.close();
}
static FastScanner in;
static PrintWriter out;
static class FastScanner {
BufferedReader in;
StringTokenizer st;
public FastScanner(BufferedReader in) {
this.in = in;
}
public String nextToken() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(in.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(nextToken());
}
public long nextLong() {
return Long.parseLong(nextToken());
}
public double nextDouble() {
return Double.parseDouble(nextToken());
}
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class Other {
public static void main(String[] args) throws NumberFormatException, IOException {
//BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
Scanner in = new Scanner(System.in);
String[] s = in.nextLine().split(" ");
char start = s[0].charAt(0);
char end = s[1].charAt(0);
int n = Integer.parseInt(in.nextLine());
n %= 4;
char[] arr = {'^', '>', 'v', '<'};
int ss = 0;
int e = 0;
for(int i=0; i<4; i++) {
if(arr[i] == start) {
ss = i;
}
if(arr[i] == end) {
e = i;
}
}
if( (ss + n)%4 == e && (ss + (4-n))%4 == e) {
System.out.println("undefined");
}
else if((ss + n)%4 == e) {
System.out.println("cw");
}
else if((ss + (4-n))%4 == e) {
System.out.println("ccw");
}
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
char c1, c2;
int t, n1, n2, ans1, ans2;
string s = "^>v<";
cin >> c1 >> c2 >> t;
n1 = s.find(c1);
n2 = s.find(c2);
t = t % 4;
ans1 = (n1 + t) % 4;
ans2 = (n1 - t);
if (ans2 < 0) ans2 += 4;
if (ans1 == n2 && ans2 == n2)
puts("undefined");
else if (ans1 == n2)
puts("cw");
else
puts("ccw");
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | /**
* Created by Helga on 7/31/2017.
*/
// v - 118, < - 60, ^ - 94, > - 62
import java.util.*;
public class Main {
public static void main(String... args)
{
Scanner input=new Scanner(System.in);
String buf=input.nextLine();
int begginingPosition=(int)buf.charAt(0);
int finalPosition=(int)buf.charAt(2);
int seconds=input.nextInt();
int begin=0;int end=0;
int[] positions=new int[5];
positions[0]=0;
positions[1]=118;
positions[2]=60;
positions[3]=94;
positions[4]=62;
boolean beginDone=false,endDone=false;
for(int i=1;i<=4;i++)
{
if(begginingPosition==positions[i])
{
begin=i;
beginDone=true;
}
if(finalPosition==positions[i])
{
end=i;
endDone=true;
}
if(beginDone&&endDone)
{
break;
}
}
int connection=seconds%4;
if(connection==2||connection==0)
{
System.out.println("undefined");
return;
}
int difference=(end-begin);
if(difference<0)
{
difference=4+difference;
}
if (difference==connection)
{
System.out.println("cw");
}
else
{
System.out.println("ccw");
}
//System.out.println(begginingPosition+" "+finalPosition+" "+seconds+" "+connection+" "+end+" "+begin+" "+difference);
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main(void) {
char start, end;
int n;
int spinner[300];
spinner['<'] = 0;
spinner['^'] = 1;
spinner['>'] = 2;
spinner['v'] = 3;
scanf(" %c %c", &start, &end);
scanf(" %d", &n);
n %= 4;
if (n == 1 || n == 3) {
if ((spinner[start] + n) % 4 == spinner[end])
cout << "cw" << endl;
else
cout << "ccw" << endl;
} else
cout << "undefined" << endl;
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | state = {'^': 1, '>': 2, 'v': 3, '<': 4}
a, b = (state[x] for x in input().split())
n = int(input()) % 4
if (b - a) % 2 == 1 and n % 2 == 1:
if (b - a) % 4 == 1:
print('cw' if n == 1 else 'ccw')
pass
elif (b - a) % 4 == 3:
print('cw' if n == 3 else 'ccw')
pass
else:
print('undefined')
else:
print('undefined')
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #!/usr/bin/python3
def main():
start, end = input().split()
time = int(input())
clock = "v<^>"
if not (time%2):
print("undefined")
elif (clock[(clock.index(start) + time)%4] == end):
print("cw")
else:
print("ccw")
if __name__ == "__main__": main()
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | start, end = input().split()
n = int(input()) % 4
if start == 'v':
start = 0
elif start == '<':
start = 1
elif start == '^':
start = 2
elif start == '>':
start = 3
if end == 'v':
end = 0
elif end == '<':
end = 1
elif end == '^':
end = 2
elif end == '>':
end = 3
temp1 = (4 + end - start) % 4
temp2 = (4 + start - end) % 4
if temp1 == temp2 == n:
print('undefined')
elif temp1 == n:
print('cw')
elif temp2 == n:
print('ccw')
else:
print('ERROR')
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
char c, d;
cin >> c >> d;
int n;
cin >> n;
if (c + d == '<' + '>' || c + d == '^' + 'v' || c == d)
cout << "undefined";
else if (c == '<' && d == '^' || c == '^' && d == '>' ||
c == '>' && d == 'v' || c == 'v' && d == '<')
if (n % 4 == 1)
cout << "cw";
else
cout << "ccw";
else if (n % 4 == 1)
cout << "ccw";
else
cout << "cw";
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | s, f = input().split()
d = {
'^': 0,
'>': 1,
'v': 2,
'<': 3,
}
s = d[s]
f = d[f]
n = int(input())
cw = (s + n) % 4
if (abs(f - s) == 2) or (s == f):
print('undefined')
elif f == cw:
print('cw')
else:
print('ccw') | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | poss = {
'^': 0,
'>': 1,
'v': 2,
'<': 3
}
sp, ep = input().split()
ss = int(input())
sp = poss[sp]
ep = poss[ep]
ss = (ss) % 4
if ss % 2 == 0:
print('undefined')
elif (sp + ss) % 4 == ep:
print('cw')
else:
print('ccw')
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b) {
long long int value;
if (b == 0) {
return 1;
} else if (b % 2 == 0) {
value = power(a, b / 2) % 1000000007;
return (value * value) % 1000000007;
} else {
value = power(a, b / 2) % 1000000007;
return ((a * value) % 1000000007 * (value)) % 1000000007;
}
}
int main() {
ios_base::sync_with_stdio(0);
char ch1, ch2, ch3;
long long int n;
cin >> ch1 >> ch2;
long long int a[] = {118, 60, 94, 62};
cin >> n;
long long int flag = 0, flag1 = 0;
long long int i;
long long int in, fi;
for (i = 0; i < 4; i++) {
if (ch1 == a[i]) {
in = i;
break;
}
}
n %= 4;
for (i = 0; i < 4; i++) {
if (a[i] == ch2) {
fi = i;
break;
}
}
long long int temp = in;
for (i = 0; i < n; i++) {
temp++;
temp %= 4;
}
if (temp == fi) {
flag = 1;
}
temp = in;
for (i = 0; i < n; i++) {
temp--;
if (temp == -1) {
temp = 3;
}
}
if (temp == fi) {
flag1 = 1;
}
if (flag and flag1) {
cout << "undefined";
} else if (flag) {
cout << "cw";
} else if (flag1) {
cout << "ccw";
} else {
cout << "undefined";
}
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
char[] all = {'v', '<', '^', '>'};
while (input.hasNext()){
int book = -1;
String s1 = input.next();
String s2 = input.next();
char a1 = s1.charAt(0);
char a2 = s2.charAt(0);
Integer x = input.nextInt();
x = x % 4;
for (int i=0; i<all.length; i++){
if(all[i] == a1){
book = i;
break;
}
}
int test1 = (book + x) % 4;
int test2 = (book - x + 4) % 4;
//System.out.println("1:" + a1 + " 2:" + a2 + " 3:" + x + " 4:" + book + " 5:" + test1 + " 6:" + test2);
if( all[test1] == a2 && all[test2] != a2){
System.out.println("cw");
}else if(all[test1] != a2 && all[test2] == a2){
System.out.println("ccw");
}else{
System.out.println("undefined");
}
}
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.util.*;
import java.io.*;
public final class Main {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
StringTokenizer st = new StringTokenizer(br.readLine());
char firstChar = Character.valueOf(st.nextToken().charAt(0));
char secondChar = Character.valueOf(st.nextToken().charAt(0));
st = new StringTokenizer(br.readLine());
int numRotations = Integer.parseInt(st.nextToken());
if(numRotations == 0){
System.out.println("undefined");
return;
}
int start = 0;
switch (firstChar){
case '^':
start = 1;
break;
case '>':
start = 2;
break;
case 'v':
start = 3;
break;
case '<':
start = 4;
break;
}
int end = 0;
switch (secondChar){
case '^':
end = 1;
break;
case '>':
end = 2;
break;
case 'v':
end = 3;
break;
case '<':
end = 4;
break;
}
//System.out.println(start + " " + end);
int clockWiseRotations = 0;
int cclockWiseRotations = 0;
int startChar = start;
int endChar = end;
for(int i = 0; i<4; i++){
if(startChar!=endChar){
clockWiseRotations++;
}else{
break;
}
startChar += 1;
if(startChar > 4)
startChar = 1;
}
//System.out.println(start + " " + end);
startChar = start;
for(int i = 0; i<4; i++){
if(startChar!=endChar){
cclockWiseRotations++;
}else{
break;
}
startChar -= 1;
if(startChar == 0) {
startChar = 4;
}
}
numRotations %= 4;
//System.out.println(clockWiseRotations + " " + cclockWiseRotations);
if(numRotations != clockWiseRotations && numRotations != cclockWiseRotations || numRotations == 2 || numRotations == 0){
pw.println("undefined");
pw.close();
return;
}
if(numRotations == clockWiseRotations){
pw.println("cw");
pw.close();
return;
}else{
pw.println("ccw");
pw.close();
return;
}
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Pradyumn Agrawal coderbond007
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastReader in = new FastReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
static class TaskA {
String clock = "^>v<^>v<";
String counter = "^<v>^<v>";
public void solve(int testNumber, FastReader in, PrintWriter out) {
char[] s = in.nextCharacterArray(2);
int len = s.length;
int n = in.nextInt();
boolean undefined = false;
boolean cw = false;
boolean ccw = false;
int ind1cw = clock.indexOf(s[0]);
int ind2cw = clock.indexOf(s[1], ind1cw);
int ind1ccw = counter.indexOf(s[0]);
int ind2ccw = counter.indexOf(s[1], ind1ccw);
if (Math.abs(ind1ccw - ind2ccw) == n % 4 && Math.abs(ind1cw - ind2cw) == n % 4) {
undefined = true;
} else if (Math.abs(ind1ccw - ind2ccw) == n % 4) {
ccw = true;
} else if (Math.abs(ind1cw - ind2cw) == n % 4) {
cw = true;
}
out.println(undefined ? "undefined" : (cw ? "cw" : "ccw"));
}
}
static class FastReader {
private InputStream stream;
private byte[] buf = new byte[8192];
private int curChar;
private int pnumChars;
private FastReader.SpaceCharFilter filter;
public FastReader(InputStream stream) {
this.stream = stream;
}
private int pread() {
if (pnumChars == -1) {
throw new InputMismatchException();
}
if (curChar >= pnumChars) {
curChar = 0;
try {
pnumChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (pnumChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int nextInt() {
int c = pread();
while (isSpaceChar(c))
c = pread();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = pread();
}
int res = 0;
do {
if (c == ',') {
c = pread();
}
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = pread();
} while (!isSpaceChar(c));
return res * sgn;
}
private boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}
private static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public char nextCharacter() {
int c = pread();
while (isSpaceChar(c))
c = pread();
return (char) c;
}
public char[] nextCharacterArray(int n) {
char[] chars = new char[n];
for (int i = 0; i < n; i++) {
chars[i] = nextCharacter();
}
return chars;
}
private interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int n, m;
int arr[4][4];
int f(char x) {
if (x == 94) return 0;
if (x == 62) return 1;
if (x == 118) return 2;
if (x == 60) return 3;
return 0;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int s;
char x, y;
cin >> x >> y >> s;
n = f(x);
m = f(y);
s %= 4;
arr[0][1] = 1;
arr[0][3] = 3;
arr[1][2] = 1;
arr[1][0] = 3;
arr[2][3] = 1;
arr[2][1] = 3;
arr[3][0] = 1;
arr[3][2] = 3;
if (n == m || abs(n + m) % 2 == 0) {
cout << "undefined" << endl;
return 0;
}
if (arr[n][m] == s)
cout << "cw" << endl;
else
cout << "ccw" << endl;
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.io.*;
import java.util.*;
import static java.lang.Math.*;
/**
* Created by Deepak Jain on 7/30/2017.
*/
public class Ques1_426 {
static class Scan {
private final InputStream inputStream;
private final byte[] buffer = new byte[1024];
private int currentChar;
private int numChars;
private SpaceCharFilter filter;
public Scan() {
inputStream = System.in;
}
public int read() {
if (numChars==-1)
throw new InputMismatchException();
if (currentChar >= numChars) {
currentChar = 0;
try {
numChars = inputStream.read(buffer);
}
catch (IOException e) {
throw new InputMismatchException();
}
if(numChars <= 0)
return -1;
}
return buffer[currentChar++];
}
public String nextLine() {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
}
return str;
}
public int nextInt() {
int ch = read();
while(isSpaceChar(ch))
ch = read();
int sgn = 1;
if (ch == '-') {
sgn = -1;
ch = read();
}
int res = 0;
do {
if(ch < '0' || ch > '9')
throw new InputMismatchException();
res *= 10;
res += ch - '0';
ch = read();
}
while (!isSpaceChar(ch));
return res * sgn;
}
public long nextLong() {
int ch = read();
while (isSpaceChar(ch))
ch = read();
int sgn = 1;
if (ch == '-') {
sgn = -1;
ch = read();
}
long res = 0;
do {
if (ch < '0' || ch > '9')
throw new InputMismatchException();
res *= 10;
res += ch - '0';
ch = read();
}
while (!isSpaceChar(ch));
return res * sgn;
}
public double nextDouble() {
int ch = read();
while (isSpaceChar(ch))
ch = read();
int sgn = 1;
if (ch == '-') {
sgn = -1;
ch = read();
}
double res = 0;
while (!isSpaceChar(ch) && ch != '.') {
if (ch == 'e' || ch == 'E')
return res * Math.pow(10, nextInt());
if (ch < '0' || ch > '9')
throw new InputMismatchException();
res *= 10;
res += ch - '0';
ch = read();
}
if (ch == '.') {
ch = read();
double m = 1;
while (!isSpaceChar(ch)) {
if (ch == 'e' || ch == 'E')
return res * Math.pow(10, nextInt());
if (ch < '0' || ch > '9')
throw new InputMismatchException();
m /= 10;
res += (ch - '0') * m;
ch = read();
}
}
return res * sgn;
}
public String readString() {
int ch = read();
while (isSpaceChar(ch))
ch = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(ch);
ch = read();
}
while (!isSpaceChar(ch));
return res.toString();
}
public boolean isSpaceChar(int ch) {
if (filter != null)
return filter.isSpaceChar(ch);
return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t' || ch == -1;
}
public String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
static class Print {
private final BufferedWriter bw;
public Print() {
this.bw=new BufferedWriter(new OutputStreamWriter(System.out));
}
public void print(Object object)throws IOException {
bw.append(""+object);
}
public void println(Object object)throws IOException {
print(object);
bw.append("\n");
}
public void close()throws IOException {
bw.close();
}
}
public static void main(String args[]) throws IOException {
Scanner sc = new Scanner(System.in);
Print pr = new Print();
String ch1 = "v<^>";
String ch2 = "v>^<";
char c1, c2;
String str = sc.nextLine();
c1 = str.toCharArray()[0];
c2 = str.toCharArray()[2];
int n, i1, l1, i2, l2;
n = sc.nextInt();
n = n % 4;
i1 = ch1.indexOf(c1);
l1 = ch1.indexOf(c2);
i2 = ch2.indexOf(c1);
l2 = ch2.indexOf(c2);
if(l1 == (i1+n)%4 && l2 == (i2+n)%4)
pr.println("undefined");
else if(l1 == (i1+n)%4)
pr.println("cw");
else if(l2 == (i2+n)%4)
pr.println("ccw");
else
pr.println("undefined");
pr.close();
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | a, b = input().split()
n = int(input())
s = '^>v<^>v'
if n & 1:
if b == s[s.find(a) + (n & 3)]:
print('cw')
else:
print('ccw')
else:
print('undefined') | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | def convert(spinner_state):
if spinner_state == 'v':
return 0
elif spinner_state == '<':
return 1
elif spinner_state == '^':
return 2
else:
return 3
start, finish = list(map(convert, input().split()))
n = int(input())
if n % 2 == 0:
print('undefined')
elif finish == (start + n % 4) % 4:
print('cw')
else:
print('ccw')
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s = "v<^>";
int n;
char ch1, ch2;
cin >> ch1 >> ch2;
cin >> n;
int i;
if (ch1 == 'v')
i = 0;
else if (ch1 == '<')
i = 1;
else if (ch1 == '^')
i = 2;
else
i = 3;
int x = 0;
int y = 0;
if (s[(i % 4 + n % 4) % 4] == ch2) x = 1;
if (s[((i - n % 4) % 4 + 4) % 4] == ch2) y = 1;
if (x == 1 && y != 1)
cout << "cw";
else if (x != 1 && y == 1)
cout << "ccw";
else
cout << "undefined";
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | start, end = raw_input().split(' ')
n = int(raw_input())
positions_cw = ['^', '>', 'v', '<']
positions_ccw = ['^', '<', 'v', '>']
n %= 4
def main():
cw = False
ccw = False
for i,pos in enumerate(positions_cw):
if pos == start:
if positions_cw[(i + n) % 4] == end:
cw = True
# return
for i,pos in enumerate(positions_ccw):
if pos == start:
if positions_ccw[(i + n) % 4] == end:
ccw = True
# return
if cw and ccw:
print('undefined')
elif cw and not ccw:
print('cw')
else:
print('ccw')
if __name__ == '__main__':
main()
| PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
char s[] = {'v', '<', '^', '>'};
char q[3], w[3];
scanf("%s%s", q, w);
scanf("%d", &n);
n %= 4;
int flag = 0;
int st, ed;
for (int i = 0; i < 4; i++) {
if (s[i] == q[0]) st = i;
if (s[i] == w[0]) ed = i;
}
int t = st;
int sum = 0, ans = 0;
while (s[t] != s[ed]) {
sum++;
t++;
if (t == 4) t = 0;
}
while (s[st] != s[ed]) {
ans++;
st--;
if (st == -1) st = 3;
}
if (sum == n && ans != n)
printf("cw\n");
else if (sum != n && ans == n)
printf("ccw\n");
else
printf("undefined\n");
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | s1, s2 = input().split()
n = int(input())
A = ['^', '>', 'v', '<']
if n % 2 == 0:
print("undefined")
elif A[A.index(s2)-1]==s1:
if n%4==3:
print('ccw')
else:
print('cw')
else:
if n%4==3:
print('cw')
else:
print('ccw')
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 20;
const int INF = 0x3f3f3f3f;
int A[maxn];
map<char, int> dp;
int main(void) {
dp['v'] = 0, dp['<'] = 1, dp['^'] = 2, dp['>'] = 3;
int n;
char a, b;
cin >> a >> b;
cin >> n;
n = n % 4;
if ((dp[a] + n) % 4 == dp[b] && (dp[a] - n + 4) % 4 == dp[b]) {
puts("undefined");
} else if ((dp[a] + n) % 4 == dp[b]) {
puts("cw");
} else if ((dp[a] - n + 4) % 4 == dp[b]) {
puts("ccw");
} else
cout << "undefined";
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | s,f=input().split()
n=int(input())
cw = ['v','<','^', '>']
ccw = ['v','>','^', '<']
ecw=cw[(cw.index(s)+n)%4]
eccw=ccw[(ccw.index(s)+n)%4]
if ecw==f:
if eccw!=f:
print('cw')
else:
print('undefined')
elif eccw ==f:
if ecw!=f:
print("ccw")
else:
print("undefined")
else:
print("undefined")
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.util.Scanner;
public class Problem1 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int start = convert(in.next().charAt(0));
int end = convert(in.next().charAt(0));
int n = in.nextInt();
boolean cw = (start + (n % 4)) % 4 == end;
boolean ccw = (4 + (start - (n % 4))) % 4 == end;
if (cw && !ccw)
System.out.println("cw");
else if (!cw && ccw)
System.out.println("ccw");
else
System.out.println("undefined");
}
private static int convert(char c) {
switch (c) {
case 'v':
return 0;
case '<':
return 1;
case '^':
return 2;
case '>':
return 3;
}
return -1;
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
char s1, s2;
cin >> s1 >> s2;
int n, k, ch = -1;
cin >> n;
k = n % 4;
if (k == 0 || k == 2)
ch = -1;
else {
if (s1 == '<') {
if (k == 1) {
if (s2 == '^')
ch = 1;
else if (s2 == 'v')
ch = 2;
} else if (k == 3) {
if (s2 == '^')
ch = 2;
else if (s2 == 'v')
ch = 1;
}
} else if (s1 == '^') {
if (k == 1) {
if (s2 == '>')
ch = 1;
else if (s2 == '<')
ch = 2;
} else if (k == 3) {
if (s2 == '<')
ch = 1;
else if (s2 == '>')
ch = 2;
}
} else if (s1 == '>') {
if (k == 1) {
if (s2 == '^')
ch = 2;
else if (s2 == 'v')
ch = 1;
} else if (k == 3) {
if (s2 == '^')
ch = 1;
else if (s2 == 'v')
ch = 2;
}
} else if (s1 == 'v') {
if (k == 1) {
if (s2 == '<')
ch = 1;
else if (s2 == '>')
ch = 2;
} else if (k == 3) {
if (s2 == '>')
ch = 1;
else if (s2 == '<')
ch = 2;
}
}
}
if (ch == -1)
cout << "undefined" << endl;
else if (ch == 1)
cout << "cw" << endl;
else
cout << "ccw" << endl;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.util.Scanner;
public class A834 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s = "v<^>";
char start = in.next().charAt(0);
char end = in.next().charAt(0);
int N = in.nextInt();
int startIdx = s.indexOf(start);
int endIdx = s.indexOf(end);
boolean cw = (startIdx + N)%4 == endIdx;
boolean ccw = (endIdx + N)%4 == startIdx;
System.out.println(cw ? (ccw ? "undefined" : "cw") : "ccw");
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | Toy = ['v', '<', '^', '>']
a, b = map(Toy.index, input().split())
n = int(input())
# print(a,b)
d = (b - a + 4) % 4
# print(d)
if d == 0 or d == 2:
print('undefined')
elif d == n % 4:
print('cw')
else:
print('ccw') | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | a = (94, 62, 118, 60, 94, 62, 118, 60)
b = (94, 60, 118, 62, 94, 60, 118, 62)
s = *map(ord, input().split()),
n = int(input()) % 4
if a[a.index(s[0]) + n] == s[1] and b[b.index(s[0]) + n] != s[1]:
print("cw")
elif a[a.index(s[0]) + n] != s[1] and b[b.index(s[0]) + n] == s[1]:
print("ccw")
else: print("undefined") | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
String [] s = sc.nextLine().split(" ");
int n = sc.nextInt();
String cw = "^>v<";
String ccw = "^<v>";
n%=4;
char start = s[0].charAt(0);
char end = s[1].charAt(0);
int index1=0;
int index2=0;
for (int i =0;i<4;i++)
{
if(cw.charAt(i)==start)
{
index1=i;
}
if(ccw.charAt(i)==start)
index2=i;
}
for (int i =0;i<n;i++)
{
index1++;
index2++;
if(index1==4)
index1=0;
if(index2==4)
index2=0;
//System.out.println(index1+" "+index2);
}
if(cw.charAt(index1)==ccw.charAt(index2))
System.out.println("undefined");
else if(cw.charAt(index1)==end)
System.out.println("cw");
else if(ccw.charAt(index2)==end)
System.out.println("ccw");
sc.close();
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
ios::sync_with_stdio(0);
char c1, c2, t1, t2;
long long n;
cin >> c1 >> c2;
cin >> n;
n %= 4;
t1 = c1;
for (int i = 0; i < n; i++) {
if (t1 == '^')
t1 = '>';
else if (t1 == '>')
t1 = 'v';
else if (t1 == 'v')
t1 = '<';
else if (t1 == '<')
t1 = '^';
}
t2 = c1;
for (int i = 0; i < n; i++) {
if (t2 == '^')
t2 = '<';
else if (t2 == '<')
t2 = 'v';
else if (t2 == 'v')
t2 = '>';
else if (t2 == '>')
t2 = '^';
}
if (t1 == c2 && t2 == c2) return cout << "undefined", 0;
if (t1 == c2) return cout << "cw", 0;
if (t2 == c2) cout << "ccw";
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.util.Scanner;
public class UselessToy {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int startPos = posIdx(scanner.next().charAt(0));
int endPos = posIdx(scanner.next().charAt(0));
int transitions = scanner.nextInt();
if (transitions%2==0) {
System.out.println("undefined");
return;
}
int endCW = (startPos + transitions) % 4;
int endCCW = (startPos - transitions) % 4;
if (endCCW<0) {
endCCW += 4;
}
if (endCW==endPos) {
System.out.println("cw");
} else if (endCCW == endPos) {
System.out.println("ccw");
} else {
System.out.println("undefined");
}
}
public static int posIdx(char pos) {
return pos=='v'? 0 : pos=='<' ? 1 : pos=='^'? 2 : 3;
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #!/bin/python3
import sys
y=input()
x = int(input().strip())
#v , < , ^, >
arr=[ 'v' , '<' , '^', '>' ]
for i in range(4):
if arr[i]==y[0]:
t=i
cw=(t+x)%4
ccw=(t-x)%4
#print(y[2])
if(arr[cw]==arr[ccw]):
print("undefined")
elif(arr[cw]!=y[2] and arr[ccw]!=y[2]):
print("undefined")
elif(arr[cw]==y[2]):
print("cw")
elif(arr[ccw]==y[2]):
print("ccw")
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | (a,b)=map(str,input().split())
n=int(input())
if a == 'v':
a=1
if a =='<':
a=2
if a=='^':
a=3
if a=='>':
a=4
if b== 'v':
b=1
if b=='<':
b=2
if b=='^':
b=3
if b=='>':
b=4
a=int(a)
b=int(b)%4
k=n%4
po=(a+k)
protiv=a-k
if po%4!=protiv%4:
if b==po%4:
print('cw')
else:
print('ccw')
else:
print('undefined') | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | s, e = tuple(input().split())
n = int(input())
s1, s2 = "v<^>", "v>^<"
print("cw" if s1[(s1.find(s) + n) % 4] == e and s2[(s2.find(s) + n) % 4] != e else "ccw" if s2[(s2.find(s) + n) % 4] == e and s1[(s1.find(s) + n) % 4] != e else "undefined")
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
char func(char a, string dir) {
if (dir == "cw") {
if (a == '^')
return '>';
else if (a == '>')
return 'v';
else if (a == 'v')
return '<';
else if (a == '<')
return '^';
} else if (dir == "ccw") {
if (a == '^')
return '<';
else if (a == '<')
return 'v';
else if (a == 'v')
return '>';
else if (a == '>')
return '^';
}
}
int main() {
char start, fin;
cin >> start >> fin;
int time;
cin >> time;
int remain = time % 4;
if (remain % 2 == 0) {
cout << "undefined" << endl;
} else {
char copy = start;
for (int i = 0; i < remain; i++) {
copy = func(copy, "cw");
}
if (copy == fin)
cout << "cw" << endl;
else
cout << "ccw" << endl;
}
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | # 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') | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.io.*;
import java.util.*;
public class C2 {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
char c1 = sc.next().charAt(0), c2 = sc.next().charAt(0);
int n = sc.nextInt();
if(n % 4 == 0 || n % 4 == 2)
out.println("undefined");
else if(n % 4 == 1)
out.println(get(c1, c2));
else
out.println(get(c2, c1));
out.close();
}
static String get(char c1, char c2)
{
String s = "v<^>";
int i = s.indexOf(c1), j = s.indexOf(c2);
if((i + 1) % 4 == j)
return "cw";
return "ccw";
}
static class Scanner
{
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));}
public Scanner(FileReader s) throws FileNotFoundException { br = new BufferedReader(s);}
public String next() throws IOException
{
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {return Integer.parseInt(next());}
public long nextLong() throws IOException {return Long.parseLong(next());}
public String nextLine() throws IOException {return br.readLine();}
public double nextDouble() throws IOException { return Double.parseDouble(next()); }
public boolean ready() throws IOException {return br.ready();}
}
} | JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.util.*;
public class MyClass {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
char r=scan.next().charAt(0),l=scan.next().charAt(0);
int n=scan.nextInt(),x=0,y=0;
char a [] = {'v','<','^','>'},b [] = {'v','>','^','<'};
for (int i=0;i<4;i++){if(a[i]==r)x=i;if(b[i]==r)y=i;}
if(n%2==0) System.out.print("undefined");
else if(a[(x+n%4)%4]==l)System.out.print("cw");
else if (b[(y+n%4)%4]==l)System.out.print("ccw");
}
} | JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import sys
spinner = input()
n = int(input())
if n > 4:
n = n % 4
clock = 'v<^>v<^>'
clockr ='>^<v>^<v'
cw = ccw = 0
p = clock.index(spinner[0])
p2 = clockr.index(spinner[0])
if clock[p+n] == spinner[2]:
cw = 1
if clockr[p2+n] == spinner[2]:
ccw = 1
if cw == 1 and ccw == 0:
print('cw')
elif ccw == 1 and cw == 0:
print('ccw')
else:
print('undefined')
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | begin, end = input().split()
begin = str(begin)
end = str(end)
n = int(input())
arrayPosicoes = ["^", ">", "v", "<"]
finalPosition = n % 4
verifyClockWise = False
verifyCounterClock = False
parameter = arrayPosicoes.index(begin)
#clockWise
while finalPosition != 0:
if parameter != 3:
parameter += 1
else:
parameter = 0
finalPosition -= 1
if arrayPosicoes[parameter] == end:
verifyClockWise = True
finalPosition2 = n % 4
parameter2 = arrayPosicoes.index(begin)
while finalPosition2 != 0:
if parameter2 != 0:
parameter2 -= 1
else:
parameter2 = 3
finalPosition2 -= 1
if arrayPosicoes[parameter2] == end:
verifyCounterClock = True
if verifyClockWise == True and verifyCounterClock == False:
print("cw")
elif verifyClockWise == False and verifyCounterClock == True:
print("ccw")
else:
print("undefined") | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
char a, b;
cin >> a >> b;
long long n;
cin >> n;
n = n % 4;
if (n == 0) {
cout << "undefined";
return 0;
}
if (n == 1) {
if (a == 'v') {
if (b == '>') {
cout << "ccw";
return 0;
}
if (b == '<') {
cout << "cw";
return 0;
}
}
if (a == '>') {
if (b == 'v') {
cout << "cw";
return 0;
}
if (b == '^') {
cout << "ccw";
return 0;
}
}
if (a == '^') {
if (b == '>') {
cout << "cw";
return 0;
}
if (b == '<') {
cout << "ccw";
return 0;
}
}
if (a == '<') {
if (b == '^') {
cout << "cw";
return 0;
}
if (b == 'v') {
cout << "ccw";
return 0;
}
}
}
if (n == 2) {
cout << "undefined";
return 0;
}
if (n == 3) {
if (a == 'v') {
if (b == '>') {
cout << "cw";
return 0;
}
if (b == '<') {
cout << "ccw";
return 0;
}
}
if (a == '>') {
if (b == 'v') {
cout << "ccw";
return 0;
}
if (b == '^') {
cout << "cw";
return 0;
}
}
if (a == '^') {
if (b == '>') {
cout << "ccw";
return 0;
}
if (b == '<') {
cout << "cw";
return 0;
}
}
if (a == '<') {
if (b == '^') {
cout << "ccw";
return 0;
}
if (b == 'v') {
cout << "cw";
return 0;
}
}
}
cout << "undefined";
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.util.*;
import java.io.*;
public class J {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
char s1 = in.next().charAt(0);
char s2 = in.next().charAt(0);
int n = in.nextInt();
n %= 4;
char c1 = s1;
char c2 = s1;
for (int i = 0; i < n; i++) {
c1 = nextSpin(c1);
c2 = prevSpin(c2);
}
if (c1 == s2 && c2 == s2) {
System.out.println("undefined");
} else if (c1 == s2) {
System.out.println("cw");
} else if (c2 == s2) {
System.out.println("ccw");
} else {
System.out.println("undefined");
}
}
public static char nextSpin(char c) {
if (c == '<') {
return '^';
}
if (c == '^') {
return '>';
}
if (c == '>') {
return 'v';
}
return '<';
}
public static char prevSpin(char c) {
if (c == '<') {
return 'v';
}
if (c == 'v') {
return '>';
}
if (c == '>') {
return '^';
}
return '<';
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | s = ['^', '>', 'v', '<']
fe = input()
f,e = fe.split()
n = int(input())
b = s.index(f)
e = s.index(e)
if n % 2 == 0:
print('undefined')
else:
n = n % 4
if (b + n) % 4 == e:
print('cw')
else:
print('ccw')
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | s, e = input().split()
d = dict()
d['^'] = 0
d['<'] = 1
d['v'] = 2
d['>'] = 3
n = int(input()) % 4
s = d[s]
e = d[e]
l = 0
r = 0
if (n + s) % 4 == e:
l = 1
if (s - n) % 4 == e:
r = 1
if l + r == 2:
print('undefined')
elif r == 1:
print('cw')
else:
print('ccw') | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.util.*;
import java.lang.*;
import java.io.*;
public class Solution
{
public static void main (String[] args) throws IOException, NumberFormatException
{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String[] s= bf.readLine().split(" ");
String strt,end;
strt = s[0];
end = s[1];
int n;
n = Integer.parseInt(bf.readLine());
n = n%4;
String[] cw = new String[4];
String[] ccw = new String[4];
cw[0] = "v";
cw[1] = "<";
cw[2] = "^";
cw[3] = ">";
ccw[0] = "v";
ccw[1] = ">";
ccw[2] = "^";
ccw[3] = "<";
int i=0,j=0;
int flag1 = 0,flag2 = 0;
for(; i <= 3&&j <= 3;) {
if(cw[i].equals(strt)) {
//cout<<i<<" "<<j<<" "<<n<<endl;
flag1 = 1;
}
else {
i++;
}
if(ccw[j].equals(strt)) {
//cout<<i<<" "<<j<<" "<<n<<endl;
flag2 = 1;
}
else {
j++;
}
if(flag1!=0 && flag2!=0)break;
}
if(cw[(i+n)%4].equals(ccw[(j+n)%4])) System.out.println("undefined");
else if(cw[(i+n)%4].equals(end)) {
System.out.println("cw");
}
else {
System.out.println("ccw");
}
}
} | JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.util.Scanner;
public class A834
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
String str=in.nextLine();
int n=in.nextInt();
char st=str.charAt(0);
char end=str.charAt(2);
n=n%4;
if(n==0)
{
System.out.println("undefined");
}
else if(n==1)
{
if(st==118)
{
if(end==60)
{
System.out.println("cw");
}
else
{
System.out.println("ccw");
}
}
else if(st==60)
{
if(end==94)
{
System.out.println("cw");
}
else
{
System.out.println("ccw");
}
}
else if(st==94)
{
if(end==62)
{
System.out.println("cw");
}
else
{
System.out.println("ccw");
}
}
else if(st==62)
{
if(end==118)
{
System.out.println("cw");
}
else
{
System.out.println("ccw");
}
}
}
else if(n==2)
{
System.out.println("undefined");
}
else if(n==3)
{
if(st==118)
{
if(end==62)
{
System.out.println("cw");
}
else
{
System.out.println("ccw");
}
}
else if(st==60)
{
if(end==118)
{
System.out.println("cw");
}
else
{
System.out.println("ccw");
}
}
else if(st==94)
{
if(end==60)
{
System.out.println("cw");
}
else
{
System.out.println("ccw");
}
}
else if(st==62)
{
if(end==94)
{
System.out.println("cw");
}
else
{
System.out.println("ccw");
}
}
}
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class A {
public static void main(String[] args) throws IOException {
File inputFile = new File("entrada");
if (inputFile.exists())
System.setIn(new FileInputStream(inputFile));
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringBuilder out = new StringBuilder();
String line;
char[] spin = new char[256];
spin['^'] = 0; spin['>'] = 1; spin['v'] = 2; spin['<'] = 3;
spin[0] = '^'; spin[1] = '>'; spin[2] = 'v'; spin[3] = '<';
while ((line = in.readLine()) != null) {
String[] w = line.trim().split(" ");
int n = Integer.parseInt(in.readLine().trim());
if(n == 0) out.append("undefined\n");
else{
int a = spin[w[0].charAt(0)], b = spin[w[1].charAt(0)];
int dif = n % 4;
boolean cw = true, ccw = true;
cw &= spin[b] == spin[(a + dif) % 4];
ccw &= spin[b] == spin[(4 + (a - dif) % 4) % 4];
out.append((cw && ccw) || (!cw && !ccw) ? "undefined" : cw ? "cw" : "ccw" ).append('\n');
}
}
System.out.print(out);
}
public static Integer[] readInts(String line) {
StringTokenizer st = new StringTokenizer(line.trim());
Integer a[] = new Integer[st.countTokens()], index = 0;
while (st.hasMoreTokens())
a[index++] = Integer.parseInt(st.nextToken());
return a;
}
public static Long[] readLongs(String line) {
StringTokenizer st = new StringTokenizer(line.trim());
Long a[] = new Long[st.countTokens()];
int index = 0;
while (st.hasMoreTokens())
a[index++] = Long.parseLong(st.nextToken());
return a;
}
public static Double[] readDoubles(String line) {
StringTokenizer st = new StringTokenizer(line.trim());
Double a[] = new Double[st.countTokens()];
int index = 0;
while (st.hasMoreTokens())
a[index++] = Double.parseDouble(st.nextToken());
return a;
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;
public class A {
public static void main (String[] args) {new A();}
A() {
FastScanner fs = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
char start = fs.next().charAt(0);
char finish = fs.next().charAt(0);
boolean[] a = new boolean[2];
int go = fs.nextInt() % 4;
char r1 = start, r2 = start;
for(int i = 0; i < go; i++) r1 = clockwise(r1);
for(int i = 0; i < go; i++) r2 = cclockwise(r2);
a[0] = r1 == finish;
a[1] = r2 == finish;
if(a[0] && a[1]) out.println("undefined");
else if(a[0]) out.println("cw");
else if(a[1]) out.println("ccw");
else out.println("undefined");
out.close();
}
char cclockwise (char c) {
if(c == '^') return '<';
if(c == '<') return 'v';
if(c == 'v') return '>';
return '^';
}
char clockwise (char c) {
if(c == '^') return '>';
if(c == '>') return 'v';
if(c == 'v') return '<';
return '^';
}
void sort (int[] a) {
int n = a.length;
for(int i = 0; i < 1000; i++) {
Random r = new Random();
int x = r.nextInt(n), y = r.nextInt(n);
int temp = a[x];
a[x] = a[y];
a[y] = temp;
}
Arrays.sort(a);
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
// br = new BufferedReader(new FileReader("testdata.out"));
st = new StringTokenizer("");
} catch (Exception e){e.printStackTrace();}
}
public String next() {
if (st.hasMoreTokens()) return st.nextToken();
try {st = new StringTokenizer(br.readLine());}
catch (Exception e) {e.printStackTrace();}
return st.nextToken();
}
public int nextInt() {return Integer.parseInt(next());}
public long nextLong() {return Long.parseLong(next());}
public double nextDouble() {return Double.parseDouble(next());}
public String nextLine() {
String line = "";
try {line = br.readLine();}
catch (Exception e) {e.printStackTrace();}
return line;
}
public Integer[] nextIntegerArray(int n) {
Integer[] a = new Integer[n];
for(int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
public int[] nextIntArray(int n) {
int[] a = new int[n];
for(int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
public char[] nextCharArray() {return nextLine().toCharArray();}
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | ordem = "v<^>"
entrada = input()
c = entrada[0]
f = entrada[2]
n = int(input()) % 4
for i in range(len(ordem)):
if ordem[i] == c:
posComeco = i
break
cw = (posComeco + n) % 4
ccw = (posComeco - n) % 4
if n % 2 == 0:
print("undefined")
elif f == ordem[cw]:
print("cw")
elif f == ordem[ccw]:
print("ccw")
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long T, i, j, n;
char c[2], ca[4] = {'v', '<', '^', '>'}, a, b;
cin >> a >> b;
map<char, long long> m;
m[ca[0]] = 1;
m[ca[1]] = 2;
m[ca[2]] = 3;
m[ca[3]] = 4;
cin >> n;
n = n % 4;
if (n == 0)
cout << "undefined" << endl;
else if (m[a] <= m[b]) {
if (m[b] - m[a] == 2)
cout << "undefined" << endl;
else if (m[b] - m[a] == n)
cout << "cw" << endl;
else if (4 - m[b] + m[a] == n)
cout << "ccw" << endl;
else
cout << "undefined" << endl;
} else {
if (m[a] - m[b] == 2)
cout << "undefined" << endl;
else if (4 - m[a] + m[b] == n)
cout << "cw" << endl;
else if (m[a] - m[b] == n)
cout << "ccw" << endl;
else
cout << "undefined" << endl;
}
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | a,b=input().split()
n=int(input())
l=['v','<','^','>']
i=l.index(a)
j=l.index(b)
if (j-i+4)%4==0 or (j-i+4)%4==2:
print('undefined')
elif (j-i+4)%4==n%4:
print('cw')
else:
print('ccw') | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 |
symbols = raw_input().strip().split()
rotations = int(raw_input().strip())
rotations = rotations % 4
cw_list = ['v', '<', '^', '>']
cw_map = {'v':0, '<':1, '^':2, '>':3}
f_idx = cw_map[symbols[0]]
s_idx_cw = (f_idx + rotations) % 4
s_idx_ccw = (f_idx - rotations) % 4
#print s_idx_cw
#print s_idx_ccw
if s_idx_cw == s_idx_ccw:
print "undefined"
elif cw_list[s_idx_cw] == symbols[1]:
print "cw"
elif cw_list[s_idx_ccw] == symbols[1]:
print "ccw"
| PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | a=[118,60,94,62]
length=len(a)
str1=map(ord,raw_input("").split())
f=str1[0]
s=str1[1]
posf=a.index(f)
poss=a.index(s)
n=int(raw_input(""))
rem=n%4
if rem==0 or rem==2:
print "undefined"
else:
temp=posf
flagcw=True
flagccw=True
rem1=rem
while rem!=0:
#cw
if temp==length-1:
temp=0
else:
temp+=1
rem-=1
if temp!=poss:
flagcw=False
#ccw
while rem1!=0:
if posf==0:
posf=length-1
else:
posf-=1
rem1-=1
if posf!=poss:
flagccw=False
if flagcw==True and flagccw==False:
print "cw"
elif flagccw==True and flagcw==False:
print "ccw"
else:
print "undefined" | PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | dic = {'^': 0, '>': 1, 'v': 2, '<': 3}
chars = raw_input().split()
start = dic[chars[0]]
end = dic[chars[1]]
n = int(raw_input())
if (end % 4 == (start + n) % 4) and (end % 4 == (start - n) % 4):
print "undefined"
elif end % 4 == (start + n) % 4:
print "cw"
else:
print "ccw"
| PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | /**
* @(#)ADIK.java
*
* ADIK application
*
* @author
* @version 1.00 2017/10/19
*/
import java.util.*;
public class ADIK {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String[] spun = new String[] { "^", ">", "v", "<" };
String[] line = input.nextLine().split(" ");
int N = input.nextInt();
int startIndex = 0;
for (int i = 0; i < spun.length; i++)
if (line[0].equals(spun[i]))
startIndex = i;
boolean right = false;
boolean left = false;
if (spun[((N % 4) + startIndex) % 4].equals(line[1]))
right = true;
if (spun[(startIndex - (N % 4)) < 0 ? 4 + (startIndex - (N % 4)) : (startIndex - (N % 4)) % 4].equals(line[1]))
left = true;
if ((!right && !left) || (right && left))
System.out.print("undefined");
else if (right)
System.out.print("cw");
else
System.out.print("ccw");
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
const int MAX_LEN = 1010;
using namespace std;
template <typename U, typename V>
string to_string(pair<U, V>);
string to_string(const string& e_) { return "\"" + e_ + "\""; }
string to_string(char e_) { return "\'" + string(1, e_) + "\'"; }
string to_string(bool e_) { return e_ ? "true" : "false"; }
template <typename T>
string to_string(T e_) {
string s_ = "[ ";
for (const auto& x_ : e_) s_ += to_string(x_) + " ";
return s_ + "]";
}
template <typename U, typename V>
string to_string(pair<U, V> e_) {
return "(" + to_string(e_.first) + ", " + to_string(e_.second) + ")";
}
void dbg_str() { ; }
template <typename U, typename... V>
void dbg_str(U u, V... v) {
;
dbg_str(v...);
}
char cw[] = {'v', '<', '^', '>'};
char ccw[] = {'v', '>', '^', '<'};
int n;
char s, e;
int main() {
scanf("%c %c", &s, &e);
scanf("%d", &n);
bool cwt = false;
bool ccwt = false;
n = n % 4;
int i;
for (i = 0; i < 4; i++)
if (cw[i] == s) break;
int t = n;
while (t--) i = (i + 1) % 4;
if (cw[i] == e) {
cwt = true;
}
for (i = 0; i < 4; i++)
if (ccw[i] == s) break;
while (n--) i = (i + 1) % 4;
if (ccw[i] == e) {
ccwt = true;
}
if (ccwt && cwt)
printf("undefined\n");
else if (cwt)
printf("cw\n");
else
printf("ccw\n");
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int tu(int val) { return (1 << val); }
bool iset(int mask, int id) {
if ((mask & tu(id)) != 0) return true;
return false;
}
void doset(int &mask, int id) { mask |= tu(id); }
void dounset(int &mask, int id) { mask = mask & (~tu(id)); }
template <typename T>
string tos(T a) {
stringstream ss;
string ret;
ss << a;
ss >> ret;
return ret;
}
int main() {
string st = "^>v<";
char ca, cb;
int n;
while (cin >> ca >> cb >> n) {
n = n % 4;
int ia = 0;
for (int(i) = (0); (i) < (4); (i)++) {
if (st[i] == ca) {
ia = i;
break;
}
}
int va, vb;
va = vb = 0;
if (st[(ia + n + 4) % 4] == cb) va = 1;
if (st[(ia - n + 4) % 4] == cb) vb = 1;
if (va + vb == 2)
puts("undefined");
else if (va == 1)
puts("cw");
else if (vb == 1)
puts("ccw");
else
puts("undefined");
}
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const long long N = 24;
long long n;
void solve() {
char x, y;
cin >> x >> y;
cin >> n;
map<char, long long> mp;
mp['^'] = 1;
mp['<'] = 2;
mp['v'] = 3;
mp['>'] = 0;
n = n % 4;
long long check = (mp[x] - mp[y] + 4) % 4;
if (check % 2 == 0) {
cout << "undefined";
} else if (check == n) {
cout << "cw";
} else {
cout << "ccw";
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
solve();
cout << endl;
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.io.*;
import java.util.StringTokenizer;
/**
* Created by Anton Berezin on 2/18/2017.
*/
public class UselessToy {
public static void main(String[] args) throws Exception {
try (FastScanner fastScanner = new FastScanner();
PrintWriter writer = new PrintWriter(new BufferedOutputStream(System.out))) {
String[] line = fastScanner.nextLine().split(" ");
char start = line[0].charAt(0);
char end = line[1].charAt(0);
int n = fastScanner.nextInt();
if (n % 2 == 0) {
writer.println("undefined");
} else {
String all = "^>v<";
int rounds = n % 4;
int startPos = all.indexOf(start);
int endPos = all.indexOf(end);
if (endPos == (startPos + rounds) % 4) {
writer.println("cw");
} else {
writer.println("ccw");
}
}
}
}
public static class FastScanner implements AutoCloseable {
BufferedReader bufferedReader;
StringTokenizer tokenizer;
public FastScanner() {
bufferedReader = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (tokenizer == null || !tokenizer.hasMoreElements()) {
try {
tokenizer = new StringTokenizer(bufferedReader.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return tokenizer.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 = bufferedReader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
@Override
public void close() throws IOException {
bufferedReader.close();
}
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | a = input().split(' ')
n = int(input())
st, end = a[0], a[1]
cw = ['^', '>', 'v', '<']
ccw = ['^', '<', 'v', '>']
i, j = cw.index(st), ccw.index(st)
if cw[(i+n%4)%4] == end and ccw[(j+n%4)%4] == end:
print('undefined')
elif cw[(i+n%4)%4] == end:
print('cw')
elif ccw[(j+n%4)%4] == end:
print('ccw')
else:
print('undefined') | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | st,fin=raw_input().split()
states=['^','>','v','<']
t=input()
stind=0
find=0
for i in range(len(states)):
if states[i]==st:
stind=i
if states[i]==fin:
find=i
cw=(stind+t)%4
ccw=(stind-t)%4
#print cw,ccw,find
if find==cw and find!=ccw:
print "cw"
elif ccw==find and find!=cw:
print "ccw"
else:
print "undefined"
| PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | n,t=map(str,input().split())
i=int(input())
if i<0:i=4-abs(i)%4
else:i%=4
if n=="^":a=1
elif n==">":a=2
elif n=="v":a=3
elif n=="<":a=4
if t=="^":b=1
elif t==">":b=2
elif t=="v":b=3
elif t=="<":b=4
c=b-a
if c<0:c=4-abs(c)%4
else:c%=4
if (i==0) or (i==2):print("undefined")
elif c==i:print("cw")
else:print("ccw") | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | X = input().split()
Y = int(input())
Answer = 'v<^>'
if Y % 2 == 0:
print("undefined")
exit()
if Y % 4 == 1:
print("ccw" if Answer[Answer.index(X[0]) - 1] == X[1] else "cw")
exit()
print("cw" if Answer[Answer.index(X[0]) - 1] == X[1] else "ccw")
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
string s = "v<^>";
int main() {
char c1, c2;
cin >> c1 >> c2;
int i1 = s.find(c1), i2 = s.find(c2);
int n;
cin >> n;
if (n % 2 == 0 || i1 == (i2 + 2) % 4 || c1 == c2)
cout << "undefined\n";
else {
if (n % 4 == 1) {
if ((i1 + 1) % 4 == i2)
cout << "cw\n";
else
cout << "ccw\n";
}
if (n % 4 == 3) {
if ((i1 + 3) % 4 == i2)
cout << "cw\n";
else
cout << "ccw\n";
}
}
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Scanner;
public class codeforces {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
char s = scan.next().charAt(0);
char s1 = scan.next().charAt(0);
long n = scan.nextLong();
int a=0,e=0;
if(s=='^') {
a=0;
}else if(s=='>') {
a=1;
}else if(s=='v') {
a=2;
}else if(s=='<') {
a=3;
}
if(s1=='^') {
e=0;
}else if(s1=='>') {
e=1;
}else if(s1=='v') {
e=2;
}else if(s1=='<') {
e=3;
}
n= n%4;
int x = (e-a)%4;
if(x<0) {
x+=4;
}
if(n==2 || n==0) {
System.out.println("undefined");
}else if(n == x) {
System.out.println("cw");
}else if(n == 4-x){
System.out.println("ccw");
}
}
} | JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.io.BufferedReader;
import java.util.*;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
public class tesst {
public static void main(String args[])throws Exception {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
char s1 = in.next().charAt(0);
char s2 = in.next().charAt(0);
int n = in.nextInt() %4;
if(n % 2 == 0) {
out.println("undefined");
out.flush();
return;
}
char cw[] = {'^', '>', 'v', '<'};
char ccw[] = {'^', '<', 'v', '>'};
int result =0;
int result2=0;
for(int i=0; i<4; i++) {
if(s1 == cw[i]) {
result = i+n;
if(result >=4) {
result -=4;
}
if(s2 == cw[result]) {
out.println("cw");
out.flush();
return;
}
}
if(s1 == ccw[i]) {
result2 = i+n;
if(result2 >=4) {
result2 -=4;
}
if(s2 == ccw[result2]) {
out.println("ccw");
out.flush();
return;
}
}
}
out.flush();
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class Three_Palindrome {
public static void main(String[] args)throws Throwable {
BufferedReader bf = new BufferedReader(new InputStreamReader (System.in));
PrintWriter pw = new PrintWriter(System.out, true);
String inp = bf.readLine();
int start=inp.charAt(0)=='^'? 0:inp.charAt(0)=='>'? 1:inp.charAt(0)=='v'? 2:3;
int end=inp.charAt(2)=='^'? 0:inp.charAt(2)=='>'? 1:inp.charAt(2)=='v'? 2:3;
int steps=Integer.parseInt(bf.readLine());
steps%=4;
boolean cw =false;
boolean ccw=false;
if((start+steps)%4==end)
cw=true;
int op2=(start-steps)%4;
if(op2!=0 && op2<0)
op2+=4;
if(op2==end)
ccw=true;
if(cw && !ccw)
pw.print("cw");
else if(ccw && !cw)
pw.print("ccw");
else
pw.print("undefined");
pw.close();
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
int main() {
int n, m, x1, x2;
char c, c1, c2;
while (scanf("%d", &n) != EOF) {
scanf("%c%c%c", &c1, &c, &c2);
scanf("%d", &n);
switch (c1) {
case '^':
x1 = 1;
break;
case '>':
x1 = 2;
break;
case 'v':
x1 = 3;
break;
case '<':
x1 = 4;
break;
}
switch (c2) {
case '^':
x2 = 1;
break;
case '>':
x2 = 2;
break;
case 'v':
x2 = 3;
break;
case '<':
x2 = 4;
break;
}
n = n % 4;
m = x1 - x2;
switch (n) {
case 0:
printf("undefined");
break;
case 2:
printf("undefined");
break;
case 1:
if (m == -1 || m == 3)
printf("cw");
else
printf("ccw");
break;
case 3:
if (m == 1 || m == -3)
printf("cw");
else
printf("ccw");
break;
}
}
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int a, b, n;
int get(char u) {
if (u == 'v')
return 0;
else if (u == '<')
return 1;
else if (u == '^')
return 2;
else
return 3;
}
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
char u, v;
cin >> u >> v >> n;
a = get(u);
b = get(v);
n %= 4;
if (n == 0 || n == 2)
cout << "undefined" << endl;
else if (n == 1 && (a + 1) % 4 == b)
cout << "cw" << endl;
else if (n == 3 && (a + 3) % 4 == b)
cout << "cw" << endl;
else
cout << "ccw" << endl;
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const double sn = 1e-6;
char a[2], b[2];
int n;
char arr1[] = {'v', '<', '^', '>'};
char arr2[] = {'v', '>', '^', '<'};
map<char, int> ma1;
map<char, int> ma2;
int main() {
scanf("%s%s%d", a, b, &n);
for (int i = 0; i < 4; i++) {
ma1[arr1[i]] = i;
ma2[arr2[i]] = i;
}
int v = n % 4;
if (b[0] == arr1[(ma1[a[0]] + n) % 4] && b[0] != arr2[(ma2[a[0]] + n) % 4])
printf("cw\n");
else if (b[0] == arr2[(ma2[a[0]] + n) % 4] &&
b[0] != arr1[(ma1[a[0]] + n) % 4])
printf("ccw\n");
else
printf("undefined\n");
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.util.Scanner;
public class Theuselesstoy {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
String s = input.next();
String s1 = input.next();
int n = input.nextInt();
n = n%4;
if(s.equals("^")){
if((s1.equals(">") && (n==1)) || (s1.equals("<")) && (n==3)){
System.out.println("cw");
return ;
}
else if((s1.equals("<") && n==1) || (s1.equals(">") && (n==3))){
System.out.println("ccw");
return;
}
else{
System.out.println("undefined");
return;
}
}
else if(s.equals(">")){
if((s1.equals("v") && (n==1)) || (s1.equals("^") && (n==3))){
System.out.println("cw");
return ;
}
else if(s1.equals("v") && (n==3) || (s1.equals("^") && (n==1))){
System.out.println("ccw");
return ;
}
else{
System.out.println("undefined");
return;
}
}
else if(s.equals("v")){
if(s1.equals("<") && (n==1) || (s1.equals(">") && (n==3))){
System.out.println("cw");
return;
}
else if((s1.equals("<") && (n==3)) || ( s1.equals(">") && (n==1))){
System.out.println("ccw");
return ;
}
else{
System.out.println("undefined");
return;
}
}
else{
if((s1.equals("^") && (n==1)) || (s1.equals("v") && (n==3))){
System.out.println("cw");
return ;
}
else if((s1.equals("^") && (n==3)) || (s1.equals("v") && (n==1))){
System.out.println("ccw");
return;
}
else{
System.out.println("undefined");
return;
}
}
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.io.*;
import java.math.*;
import java.util.*;
public class CODEFORCES {
private InputStream is;
private PrintWriter out;
void solve() {
String a = ns();
String c = ns();
int n = ni() % 4;
String b = "v<^>";
char ch = a.charAt(0);
int ind;
for (ind = 0; ind < b.length(); ind++)
if (b.charAt(ind) == ch)
break;
ch = c.charAt(0);
if (ch == b.charAt((ind + n) % 4) && ch == b.charAt((ind + 4 - n) % 4))
out.println("undefined");
else if (ch == b.charAt((ind + n) % 4))
out.println("cw");
else if (ch == b.charAt((ind + 4 - n) % 4))
out.println("ccw");
else
out.println("undefined");
}
void soln() throws Exception {
is = System.in;
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
solve();
out.flush();
tr(System.currentTimeMillis() - s + "ms");
}
public static void main(String[] args) throws Exception {
new CODEFORCES().soln();
}
// 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));
}
} | JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | s = input().split()
k = int(input()) % 4
pos = ['^','>','v','<']
if s[0] == '^':
st = 1
elif s[0] == '>':
st = 2
elif s[0] == 'v':
st = 3
else:
st = 4
if s[1] == '^':
fin = 1
elif s[1] == '>':
fin = 2
elif s[1] == 'v':
fin = 3
else:
fin = 4
if abs(st - fin) == 2 or st - fin == 0:
print('undefined')
else:
if (st - fin )%4 == k:
print('ccw')
else:
print('cw') | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | def main_function():
input_str = [i for i in input().split(" ")]
n = int(input())
n = n % 4
d = ["v", "<", "^", ">"]
if not n % 2:
return "undefined"
starting_index = d.index(input_str[0])
ending_index = d.index(input_str[1])
new_index_1 = starting_index + n
new_index_2 = starting_index - n
if new_index_1 > 3:
new_index_1 -= 4
if new_index_2 < 0:
new_index_2 = 4 - new_index_2
if ending_index == new_index_1:
return "cw"
return "ccw"
print(main_function()) | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.util.*;
import java.io.*;
public class cfr426a {
public static void main(String[] args) throws IOException {
char[] cw={'<','^','>','v'};
HashMap<Character,Integer> cw2=new HashMap<Character,Integer>();
char[] ccw={'<','v','>','^'};
HashMap<Character,Integer> ccw2=new HashMap<Character,Integer>();
for(int i=0;i<4;i++){
cw2.put(cw[i],i);
ccw2.put(ccw[i],i);
}
BufferedReader f=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer tk=new StringTokenizer(f.readLine().trim());
char s=tk.nextToken().charAt(0);
char e=tk.nextToken().charAt(0);
int n=Integer.parseInt(f.readLine())%4;
if(n%2==0){
System.out.println("undefined");
}
else{
if(cw[(cw2.get(s)+n)%4]==e){
System.out.println("cw");
}
else{
System.out.println("ccw");
}
}
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | start, stop = input().split()
n = int(input())
d = {'v': 2 , '<': 3, '^':0, '>':1}
if (d[start] + n) % 4 == d[stop]:
clockwise = True
else:
clockwise = False
if (d[start] - n) % 4 == d[stop]:
counter_clockwise = True
else:
counter_clockwise = False
if counter_clockwise and clockwise:
print('undefined')
elif clockwise:
print('cw')
else:
print('ccw')
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | positions = ["v", "<", "^", ">"]
s, t = input().split()
a, b = positions.index(s), positions.index(t)
n = int(input())
c1 = (a + n) % 4 == b
p = a - n
if a < n:
p = (4 - abs(p) % 4) % 4
else:
p %= 4
c2 = p == b
if c1 and c2:
print("undefined")
elif c1:
print("cw")
else:
print("ccw") | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.io.*;
import java.util.*;
import java.math.*;
public class utkarsh {
InputStream is;
PrintWriter out;
long maxl = (long) 4e18, mod = (long)1e9 + 7L;
int p[], s[], maxi = (int) 2e9, sz, np = 15485900, modi = (int)1e9 + 7;
boolean b[]; // = isPrime();
void solve(){
//sz=sieve(); //sz = 1000001;
//out.println(sz);
//Enter code here utkarsh
char s = nc();
char e = nc();
long n = nl();
n %= 4;
if(n == 0 || n == 2){
out.println("undefined");
}else{
int i, j;
int a[] = new int[]{118, 60, 94, 62};
for(i = 0; i < 4; i++){
if(s == a[i]) break;
}
for(j = 0; j < 4; j++){
if(e == a[j]) break;
}
if((i+n)%4 == j){
out.println("cw");
}else{
out.println("ccw");
}
}
}
int sieve(){
int i, j, n = np;
b = new boolean[n];
s = new int[n];
for(i = 3; i < n; i += 2) {
b[i] = true;
s[i-1] = 2;
}
b[2] = true;
s[1] = 1; //(UD)
for(i = 3; i * i <= n; i += 2) {
if ( b[i] ) {
s[i] = i;
for(j = i * i; j < n; j += i) {
b[j] = false;
if(s[j] == 0) s[j] = i;
}
}
}
p = new int[n];
p[0] = 2;
j = 1;
for(i = 3; i < n; i += 2) {
if ( b[i] ) {
p[j++] = i;
}
}
p = Arrays.copyOf(p, j);
return j;
}
long modpow(long base, long exp, long modulus) { base %= modulus; long result = 1L; while (exp > 0) { if ((exp & 1)==1) result = (result * base) % modulus; base = (base * base) % modulus; exp >>= 1; } return result;
}
public static void main(String[] args) { new utkarsh().run();
}
void run(){ is = System.in; out = new PrintWriter(System.out); solve(); out.flush();
}
byte input[] = new byte[1024];
int len = 0, ptr = 0;
int readByte(){ if(ptr >= len){ ptr = 0; try{ len = is.read(input); }catch(IOException e){ throw new InputMismatchException(); } if(len <= 0){ return -1; } } return input[ptr++];
}
boolean isSpaceChar(int c){ return !( c >= 33 && c <= 126 );
}
int skip(){ int b = readByte(); while(b != -1 && isSpaceChar(b)){ b = readByte(); } return b;
}
char nc(){ return (char)skip();
}
String ns(){ int b = skip(); StringBuilder sb = new StringBuilder(); while(!isSpaceChar(b)){ sb.appendCodePoint(b); b=readByte(); } return sb.toString();
}
int ni(){ int n = 0,b = readByte(); boolean minus = false; while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')){ b = readByte(); } if(b == '-'){ minus = true; b = readByte(); } if(b == -1){ return -1; } while(b >= '0' && b <= '9'){ n = n * 10 + (b - '0'); b = readByte(); } return minus ? -n : n;
}
long nl(){ long n = 0L; int b = readByte(); boolean minus = false; while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')){ b = readByte(); } if(b == '-'){ minus = true; b = readByte(); } while(b >= '0' && b <= '9'){ n = n * 10 + (b - '0'); b = readByte(); } return minus ? -n : n;
}
double nd(){ return Double.parseDouble(ns());
}
float nf(){ return Float.parseFloat(ns());
}
int[] na(int n){ int a[] = new int[n]; for(int i = 0; i < n; i++){ a[i] = ni(); } return a;
}
char[] ns(int n){ char c[] = new char[n]; int i,b = skip(); for(i = 0; i < n; i++){ if(isSpaceChar(b)){ break; } c[i] = (char)b; b = readByte(); } return i == n ? c : Arrays.copyOf(c,i);
}
} | JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Main {
public static void main(String args[])throws IOException {
BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
PrintWriter out=new PrintWriter(System.out);
StringTokenizer st=new StringTokenizer(sc.readLine());
char a = st.nextToken().charAt(0);
char b = st.nextToken().charAt(0);
st = new StringTokenizer(sc.readLine());
int n = ip(st.nextToken()) % 4;
String ss = "undefined";
if (n == 1) {
if (a == 'v') {
if(b=='<')
ss = "cw";
else if(b=='>')
ss = "ccw";
} else if (a == '<') {
if(b=='^')
ss = "cw";
else if(b=='v')
ss = "ccw";
} else if (a == '^') {
if(b=='>')
ss = "cw";
else if(b=='<')
ss = "ccw";
} else if (a == '>') {
if(b=='v')
ss = "cw";
else if(b=='^')
ss = "ccw";
}
}else if (n == 3) {
if (a == 'v') {
if(b=='>')
ss = "cw";
else if(b=='<')
ss = "ccw";
} else if (a == '<') {
if(b=='v')
ss = "cw";
else if(b=='^')
ss = "ccw";
} else if (a == '^') {
if(b=='<')
ss = "cw";
else if(b=='>')
ss = "ccw";
} else if (a == '>') {
if(b=='^')
ss = "cw";
else if(b=='v')
ss = "ccw";
}
}
out.println(ss);
out.close();
}
public static int ip(String s) {
return Integer.parseInt(s);
}
} | JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | s,e=input().split()
d={}
d['^']=0
d['>']=1
d['v']=2
d['<']=3
n=int(input())
n=n%4
counter=(d[e]-d[s]+4)%4
if(n==counter and n!=2 and n!=0):
print("cw")
elif(n==4-counter and n!=2 and n!=0):
print("ccw")
else:
print("undefined") | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner Ahmad =new Scanner(System.in);
String xyz;
xyz=Ahmad.nextLine();
int m,n;
char x,y,z;
x=xyz.charAt(0);
y=xyz.charAt(0);
z=xyz.charAt(2);
m=Ahmad.nextInt();
n=m%4;
for(int i=0;i<n;i++) {
if(x=='v') {
x='>';
}
else if(x=='>') {
x='^';
}
else if(x=='^') {
x='<';
}
else if(x=='<') {
x='v';
}
}
for(int i=0;i<n;i++) {
if(y=='v') {
y='<';
}
else if(y=='>') {
y='v';
}
else if(y=='^') {
y='>';
}
else if(y=='<') {
y='^';
}
}
if((x==z)&&(y==z))
System.out.println("undefined");
else if(x==z) {
System.out.println("ccw");
}
else if(y==z) {
System.out.println("cw");
}
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class ProblemA {
char[] w = new char[] { '^', '>', 'v', '<' };
BufferedReader rd;
ProblemA() throws IOException {
rd = new BufferedReader(new InputStreamReader(System.in));
compute();
}
private void compute() throws IOException {
String[] h = split(rd.readLine());
int n = pint();
n %= 4;
char c = h[0].charAt(0);
char d = h[1].charAt(0);
for(int i=0;i<n;i++) {
c = cw(c);
}
boolean cw = c == d;
c = h[0].charAt(0);
for(int i=0;i<n;i++) {
c = ccw(c);
}
boolean ccw = c == d;
if(cw && !ccw) {
out("cw");
} else if(!cw && ccw) {
out("ccw");
} else {
out("undefined");
}
}
private char cw(char c) {
for(int i=0;i<4;i++) {
if(w[i] == c) {
int j = (i+1)%4;
return w[j];
}
}
return c;
}
private char ccw(char c) {
for(int i=0;i<4;i++) {
if(w[i] == c) {
int j = (i+3)%4;
return w[j];
}
}
return c;
}
private int pint() throws IOException {
return pint(rd.readLine());
}
private int pint(String s) {
return Integer.parseInt(s);
}
private String[] split(String s) {
if(s == null) {
return new String[0];
}
int n = s.length();
int start = -1;
int end = 0;
int sp = 0;
boolean lastWhitespace = true;
for(int i=0;i<n;i++) {
char c = s.charAt(i);
if(isWhitespace(c)) {
lastWhitespace = true;
} else {
if(lastWhitespace) {
sp++;
}
if(start == -1) {
start = i;
}
end = i;
lastWhitespace = false;
}
}
if(start == -1) {
return new String[0];
}
String[] res = new String[sp];
int last = start;
int x = 0;
lastWhitespace = true;
for(int i=start;i<=end;i++) {
char c = s.charAt(i);
boolean w = isWhitespace(c);
if(w && !lastWhitespace) {
res[x++] = s.substring(last,i);
} else if(!w && lastWhitespace) {
last = i;
}
lastWhitespace = w;
}
res[x] = s.substring(last,end+1);
return res;
}
private boolean isWhitespace(char c) {
return c==' ' || c=='\t';
}
private static void out(Object x) {
System.out.println(x);
}
public static void main(String[] args) throws IOException {
new ProblemA();
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
inline int Get(char a) {
switch (a) {
case 'v':
return 0;
case '<':
return 1;
case '^':
return 2;
case '>':
return 3;
}
}
int main(void) {
int step, s, t;
char st, ed;
cin >> st >> ed >> step;
s = Get(st);
t = Get(ed);
if ((s + step) % 4 == t && ((s - step) % 4 + 4) % 4 != t)
printf("cw");
else if ((s + step) % 4 != t && ((s - step) % 4 + 4) % 4 == t)
printf("ccw");
else
printf("undefined");
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | arrowslist = ('v','<', '^', '>')
flag = True
arrows = input().split()
n = int(input()) % 4
k = arrowslist.index(arrows[0]) - arrowslist.index(arrows[1])
if k % 2 == 0:
print("undefined")
if n == 3:
flag = False
if (k == 1 or k== -3):
if flag:
print("ccw")
else:
print("cw")
if (k == -1 or k == 3):
if flag:
print("cw")
else:
print("ccw") | PYTHON3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.