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 |
import com.sun.corba.se.impl.orbutil.ORBConstants;
import java.io.PrintWriter;
import java.util.*;
import java.util.Arrays ;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.Array;
public class Test{
static PrintWriter pw = new PrintWriter(System.out);
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
static int find(long x[],long r){
int sum =0 ;
for (int i = 0; i < x.length; i++) {
if(x[i]==r) return i+1 ;
}
return sum ;
}
static int [] find2(int x[][],int temp,int y[]){
for (int i = 0; i < x.length; i++) {
int sum=0 ;
for (int j = 0; j < x.length; j++) {
sum+=x[j][i] ;
}
y[i]=sum ;
}
return y;
}
static void found(LinkedList<Integer> l1,String s,LinkedList<Integer> l2){
for (int i = 0; i < s.length()-1; i++) {
String temp ="" ;
temp +=(char)s.charAt(i);
temp +=(char)s.charAt(i+1);
if(temp.equals("AB"))l1.add(i) ;
if(temp.equals("BA"))l2.add(i) ;
}
}
static String db(String s){
StringBuilder b= new StringBuilder(s) ;
return s+(b.reverse().toString()) ;
}
static String btw(String s,char c){
StringBuilder b= new StringBuilder(s) ;
return (s+c)+(b.reverse().toString()) ;
}
public static void main(String[] args) throws IOException {
// Reader in =new Reader ();
Scanner in =new Scanner (System.in);
String s= in.nextLine();
// System.out.println(s.charAt(2));
long n = in.nextLong() ;
int t =0 ;
if(s.charAt(0)==118) t=1 ;
if(s.charAt(0)==60)t= 2 ;
if(s.charAt(0)==94)t= 3 ;
if(s.charAt(0)==62)t= 4 ;
long save= ((t+n)%4) ;
if((t+n)%4==0)save=4 ;
char o ='e' ;
if(save==1)o=118 ;
if(save==2)o=60 ;
if(save==3)o=94 ;
if(save==4)o=62 ;
if(s.charAt(0)==118) t=4 ;
if(s.charAt(0)==60)t= 3 ;
if(s.charAt(0)==94)t= 2 ;
if(s.charAt(0)==62)t= 1 ;
save= ((t+n)%4) ;
if((t+n)%4==0)save=4 ;
char o2='f' ;
if(save==4)o2=118 ;
if(save==3)o2=60 ;
if(save==2)o2=94 ;
if(save==1)o2=62 ;
// System.out.println(o2);
if(o==s.charAt(2)&&o2==s.charAt(2)){
System.out.println("undefined");
return ;
}
if(o==s.charAt(2)){
System.out.println("cw");
}else {
System.out.println
("ccw");
}
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 | def find(s,n):
a=s[0]
a2=s[2]
start=0
if a=='<':
start=0
elif a=='^':
start=1
elif a=='>':
start=2
elif a=='v':
start=3
start2=0
if a2=='<':
start2=0
elif a2=='^':
start2=1
elif a2=='>':
start2=2
elif a2=='v':
start2=3
#print(start,start2)
if (start+n)%4==start2%4 and (start-n)%4==start2%4:
print('undefined')
elif (start-n)%4==start2%4:
print('ccw')
elif (start+n)%4==start2%4:
print('cw')
s=str(raw_input())
n=int(input())
find(s,n) | PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | x, y = map(str, input().split())
n = int(input())
if x == y: print("undefined")
elif x == ">" and y == "<": print("undefined")
elif x == "<" and y == ">": print("undefined")
elif x == "^" and y == "v": print("undefined")
elif y == "^" and x == "v": print("undefined")
elif x == "^" and y == ">":
if (n - 1) % 4 == 0: print("cw")
elif (n - 3) % 4 == 0: print("ccw")
else: print("undefined")
elif x == "^" and y == "<":
if (n - 1) % 4 == 0: print("ccw")
elif (n - 3) % 4 == 0: print("cw")
else: print("undefined")
elif x == "v" and y == ">":
if (n - 1) % 4 == 0: print("ccw")
elif (n - 3) % 4 == 0: print("cw")
else: print("undefined")
elif x == "v" and y == "<":
if (n - 1) % 4 == 0: print("cw")
elif (n - 3) % 4 == 0: print("ccw")
else: print("undefined")
elif y == "^" and x == ">":
if (n - 1) % 4 == 0: print("ccw")
elif (n - 3) % 4 == 0: print("cw")
else: print("undefined")
elif y == "^" and x == "<":
if (n - 1) % 4 == 0: print("cw")
elif (n - 3) % 4 == 0: print("ccw")
else: print("undefined")
elif y == "v" and x == ">":
if (n - 1) % 4 == 0: print("cw")
elif (n - 3) % 4 == 0: print("ccw")
else: print("undefined")
elif y == "v" and x == "<":
if (n - 1) % 4 == 0: print("ccw")
elif (n - 3) % 4 == 0: print("cw")
else: print("undefined") | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | ways = ['v', '<', '^', '>'];
count = 4;
def main():
vals = filter(lambda a: len(a) > 0, map(str.strip, raw_input().split(' ')))
index_in = ways.index(vals[0])
index_out = ways.index(vals[1])
time = int(raw_input().strip())
cw = (index_in + time) % count;
ccw = ((index_in - cw) + index_in) % count;
if(cw == ccw and cw == index_out):
print "undefined"
elif(cw == index_out):
print "cw\n"
elif(ccw == index_out):
print "ccw\n"
else:
print "err %s %s %s %s" % (index_in, index_out, cw, ccw)
main() | PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
static class TaskA {
int position(char x) {
switch (x) {
case '^':
return 1;
case '>':
return 2;
case 'v':
return 3;
case '<':
return 4;
}
return 0;
}
public void solve(int testNumber, InputReader in, PrintWriter out) {
int s = position(in.nextChar());
int e = position(in.nextChar());
int n = in.nextInt();
int diffOne = Math.abs(s - e);
int diffTwo = 4 - diffOne;
if ((n - diffOne) % 4 == 0 && (n - diffTwo) % 4 == 0) {
out.println("undefined");
} else if ((n - diffOne) % 4 == 0) {
if (s > e) {
out.println("ccw");
} else {
out.println("cw");
}
} else {
if (s > e) {
out.println("cw");
} else {
out.println("ccw");
}
}
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public char nextChar() {
return next().charAt(0);
}
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | def conv(a):
if a=="v":
return 0
elif a=="<":
return 1
elif a=="^":
return 2
elif a==">":
return 3
count=[]
x,y=raw_input().split(" ")
n=input()
if (conv(x)+n)%4==conv(y):
count.append("cw")
if (conv(x)-n)%4==conv(y):
count.append("ccw")
if(len(count)==1):
print count[0]
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 | start , end = input().split(' ')
time = int(input())
time = time%4
positions = ['v','<','^','>']
pos_reverse = ['v','>','^','<']
cw = ccw = False
pos_start_cw = positions.index(start)
pos_end_cw = positions.index(end)
pos_start_ccw = pos_reverse.index(start)
pos_end_ccw = pos_reverse.index(end)
if (pos_start_cw + time)%4 == pos_end_cw:
cw = True
if (pos_start_ccw + time)%4 == pos_end_ccw:
ccw = True
if cw is True:
if ccw is False:
print('cw')
else:
print('undefined')
elif ccw is True:
if cw is False:
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 | s, e = input().split()
cw, ccw = ['^', '>', 'v', '<'], ['^', '<', 'v', '>']
n, a, b = int(input()), False, False
if cw[(n + cw.index(s)) % 4] == e:
a = True
if ccw[(n + ccw.index(s)) % 4] == e:
b = True
print("undefined" if a and b else("cw" if a and not b 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 | b,e=input().split()
n=int(input())%4
l=['v','>','^','<']
b=l.index(b)
e=l.index(e)
bccw=b
bcw=b
for _ in range(n):
bccw=(bccw+1)%4
bcw=(bcw-1+4)%4
if bccw==bcw or (bccw!=e and bcw!=e): print("undefined")
elif bccw==e: 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 | t = input()
ccwpos = ["> ^","< v","^ <","v >"]
cwpos = ["< ^","^ >","> v","v <"]
n = int(input())
if t in ccwpos:
if (n - 1)%4 == 0:
print("ccw")
else:
print("cw")
elif t in cwpos:
if (n-1)%4 == 0:
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 | arrows_dir={'v':0,'<':1,'^':2,'>':3}
st,en=input().strip().split()
arrows=['v','<','^','>']
st_pos=arrows_dir[st]
en_pos=(int(input())%4)
if((arrows[(st_pos+en_pos)%4]==en) and (arrows[(st_pos-en_pos)]==en)):
print("undefined")
elif(arrows[(st_pos+en_pos)%4]==en):
print("cw")
elif(arrows[(st_pos-en_pos)]==en):
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,en = input().split(' ')
n=int(input())
n=n%4
if n==0:
print("undefined")
elif n==1:
if (st=='^' and en=='>') or (st=='>' and en=='v') or (st=='v' and en=='<') or (st=='<' and en=='^'):
print('cw')
elif (st=='^' and en=='<') or (st=='>' and en=='^') or (st=='v' and en=='>') or (st=='<' and en=='v'):
print('ccw')
else:
print('undefined')
elif n==2:
if (st=='^' and en=='v') or (st=='>' and en=='<') or (st=='v' and en=='^') or (st=='<' and en=='>'):
print('undefined')
elif n==3:
if (st=='^' and en=='>') or (st=='>' and en=='v') or (st=='v' and en=='<') or (st=='<' and en=='^'):
print('ccw')
elif (st=='^' and en=='<') or (st=='>' and en=='^') or (st=='v' and en=='>') or (st=='<' and en=='v'):
print('cw')
else:
print('undefined')
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | spinner = ['v', '<', '^', '>']
s = input().split()
n = int(input())
if n % 2 == 0:
print('undefined')
else:
if (spinner.index(s[1]) - spinner.index(s[0]) + 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 | # -*- coding: utf-8 -*-
"""
Created on Thu Dec 19 19:28:14 2019
@author: HP
"""
DIRS = ['v', '<', '^', '>']
a, b = map(DIRS.index, input().split())
n = int(input())
#print(a)
#print(b)
delta = (b - a + 4) % 4
#print(delta)
if delta == 0 or delta == 2:
print('undefined')
elif delta == 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 | positions = ">v<^"
s, t = input().split()
n = int(input())
si = positions.index(s)
ti_cw = positions[(si + n) % 4]
ti_ccw = positions[(si - n) % 4]
if n % 2 == 0:
print('undefined')
elif t == ti_cw:
print('cw')
elif t == ti_ccw:
print('ccw')
else:
assert False | 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;
using ll = long long int;
using dl = double;
const int N = 2e5 + 10;
ll aarray[200000 + 10];
ll magic[101][101];
vector<ll> primes;
bool prime[1000001];
int main() {
ios_base::sync_with_stdio(false);
string str;
ll i, j, n, m, k, t;
char ch1, ch2;
str = "v<^>v<^";
cin >> ch1 >> ch2;
cin >> n;
n %= 4;
ll flag = 0, fl = 0;
for (i = 0; i < str.length(); i++) {
if (str[i] == ch1 && str[i + n] == ch2) {
flag++;
}
if (str[i] == ch1 && str[i - n] == ch2 && i - n >= 0) {
fl++;
}
}
if (fl && flag) {
cout << "undefined" << endl;
return 0;
}
if (flag) {
cout << "cw" << endl;
return 0;
}
if (fl) {
cout << "ccw" << endl;
return 0;
}
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | scw = ['0', 'v', '<', '^', '>']
sccw = ['0', 'v', '>', '^', '<']
c1, c2 = input().split()
n = int(input())
n = n % 4
n1, n2 = scw.index(c1), sccw.index(c1)
if 4 - n1 >= n:
a1 = scw[n1+n]
else:
a1 = scw[(n1+n)%4]
if 4 - n2 >= n:
a2 = sccw[n2+n]
else:
a2 = sccw[(n2+n)%4]
if a1 == c2 and a2 == c2:
print("undefined")
elif a1 == c2 and a2 != c2:
print('cw')
else:
print('ccw')
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | d = 'v<^>'
a, b = map(d.find, input().split())
n, a = int(input()), (b - a + 4) % 4
print('undefined' if a == 2 or a == 0 else 'cw' if n % 4 == a else 'ccw')
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | a = 'v<^>'
f,s = raw_input().split()
steps = int(raw_input())
i = a.find(f)
cw = a[(i + steps)%4] == s
ccw = a[(i - steps)%4] == s
if cw and ccw:
print "undefined"
elif cw:
print "cw"
elif ccw:
print "ccw"
else:
print "undefined"
| PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
char c, c1;
cin >> c >> c1;
int n;
cin >> n;
int val = n % 4;
if (c == c1) {
cout << "undefined" << endl;
return 0;
}
if ((c == '<' && c1 == '>') || (c == '>' && c1 == '<') ||
(c == 'v' && c1 == 94) || (c == 94 && c1 == 'v')) {
cout << "undefined" << endl;
return 0;
}
if (c == '<' && c1 == 'v') {
if (val == 3) {
cout << "cw" << endl;
} else
cout << "ccw";
return 0;
}
if (c == 'v' && c1 == '<') {
if (val == 1) {
cout << "cw" << endl;
} else
cout << "ccw";
return 0;
}
if (c == '>' && c1 == 94) {
if (val == 3) {
cout << "cw" << endl;
} else
cout << "ccw";
return 0;
}
if (c == 94 && c1 == '>') {
if (val == 1) {
cout << "cw" << endl;
} else
cout << "ccw";
return 0;
}
if (c == 'v' && c1 == '>') {
if (val == 3) {
cout << "cw" << endl;
} else
cout << "ccw";
return 0;
}
if (c == '>' && c1 == 'v') {
if (val == 1) {
cout << "cw" << endl;
} else
cout << "ccw";
return 0;
}
if (c == '<' && c1 == 94) {
if (val == 1) {
cout << "cw" << endl;
} else
cout << "ccw";
return 0;
}
if (c == 94 && c1 == '<') {
if (val == 3) {
cout << "cw" << endl;
} 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 | DIRS = ['v', '<', '^', '>']
a, b = map(DIRS.index, input().split())
n = int(input())
delta = (b - a + 4) % 4
if delta == 0 or delta == 2:
print('undefined')
elif delta == n % 4:
print('cw')
else:
print('ccw') | 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, g = input().split()
n = int(input())
cw = {'<': 1, '^': 2, '>': 3, 'v': 4}
ccw = {'<': 1, '^': 4, '>': 3, 'v': 2}
n = n % 4
d1 = cw[g] - cw[s]
d2 = ccw[g] - ccw[s]
if (d1 < 0):
d1 += 4
if (d2 < 0):
d2 += 4
result = ''
if (d1 == n and d2 != n):
result = 'cw'
elif (d2 == n and d1 != n):
result = 'ccw'
else:
result = 'undefined'
print(result) | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | s,e=input().split()
n=int(input())
ccw='^<v>^<v>'
cw='^>v<^>v<'
i=n%4
if cw[cw.index(s)+i]==ccw[ccw.index(s)+i]==e:
print("undefined")
elif ccw[ccw.index(s)+i]==e:
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 | start,end = input().split()
n = int(input())
cw = {0:'^',1:'>',2:'v',3:'<'}
dcw = {'^':0,'>':1,'v':2,'<':3}
ccw = {0:'^',1:'<',2:'v',3:'>'}
dccw = {'^':0,'<':1,'v':2,'>':3}
modulo = n%4
if cw[(dcw[start]+modulo)%4]==ccw[(dccw[start]+modulo)%4]:
print('undefined')
elif cw[(dcw[start]+modulo)%4]==end:
print('cw')
elif ccw[(dccw[start]+modulo)%4]==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.util.*;
import java.lang.*;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.io.*;
public class Solution {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
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());
}
public int[] readIntArray(int n) {
int[] arr = new int[n];
for(int i=0; i<n; ++i)
arr[i]=nextInt();
return arr;
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try{
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static String solve(char a, char b, int t) {
return "";
}
public static void main(String args[]) throws IOException {
FastReader sc = new FastReader();
long start = System.currentTimeMillis();
String s = sc.nextLine();
int n = sc.nextInt();
int[] pos = new int[256];
pos[118]=0;
pos[60]=1;
pos[94]=2;
pos[62]=3;
if(n%2==0)
System.out.println("undefined");
else if((pos[s.charAt(2)]-pos[s.charAt(0)]+4)%4==n%4)
System.out.println("cw");
else
System.out.println("ccw");
//System.out.println(solve(a,b,t));
long end = System.currentTimeMillis();
NumberFormat formatter = new DecimalFormat("#0.00000");
//System.out.print("Execution time is " + formatter.format((end - start) / 1000d) + " seconds");
}
}
| 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
positions = {"v":1,"<":2,"^":3,">":4}
s,e = raw_input().split()
s = positions[s]
e = positions[e]
n = int(raw_input())
if n == 0 or n%2==0:
print "undefined"
else:
x = n%4
if abs(s+x)%4 == e%4:
print "cw"
else:
if abs(4+s-x)%4 == e%4:
print "ccw"
else:
print "undefined" | PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | set = ('v','<','^', '>')
start, stop = input().strip().split(" ")
time = int(input())
rotations = time%4
startPos = set.index(start)
endPos = set.index(stop)
res = (startPos - endPos)%4
if res == 3:
if rotations == 1:
print("cw")
else:
print("ccw")
elif res == 1:
if rotations == 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 | x,y = input().split()
z =int(input())%4
if x == '^' and y == 'v': print("undefined")
elif x == 'v' and y == '^': print("undefined")
elif x == '<' and y == '>': print("undefined")
elif x == '>' and y == '<': print("undefined")
elif x == '>' and y == '>': print("undefined")
elif x == '<' and y == '<': print("undefined")
elif x == '^' and y == '^': print("undefined")
elif x == 'v' and y == 'v': print("undefined")
else:
if x == '^' and y =='>' and z == 1: print("cw")
if x == '^' and y =='<' and z == 3: print("cw")
if x == '^' and y =='<' and z == 1: print("ccw")
if x == '^' and y =='>' and z == 3: print("ccw")
if x == '>' and y =='v' and z == 1: print("cw")
if x == '>' and y =='^' and z == 3: print("cw")
if x == '>' and y =='^' and z == 1: print("ccw")
if x == '>' and y =='v' and z == 3: print("ccw")
if x == 'v' and y =='<' and z == 1: print("cw")
if x == 'v' and y =='>' and z == 3: print("cw")
if x == 'v' and y =='>' and z == 1: print("ccw")
if x == 'v' and y =='<' and z == 3: print("ccw")
if x == '<' and y =='^' and z == 1: print("cw")
if x == '<' and y =='v' and z == 3: print("cw")
if x == '<' and y =='v' and z == 1: print("ccw")
if x == '<' and y =='^' and z == 3: print("ccw") | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
char a, b;
cin >> a >> b;
int x;
cin >> x;
x = x % 4;
int t, y;
switch (a) {
case '^': {
t = 1;
break;
}
case '<': {
t = 2;
break;
}
case 'v': {
t = 3;
break;
}
case '>': {
t = 4;
break;
}
}
switch (b) {
case '^': {
y = 1;
break;
}
case '<': {
y = 2;
break;
}
case 'v': {
y = 3;
break;
}
case '>': {
y = 4;
break;
}
}
if (x == 2 or x == 0) {
cout << "undefined";
return 0;
} else {
int t1 = (t + x) % 4;
if (t1 <= 0) t1 = 4 + t1;
int t2 = (t - x) % 4;
if (t2 <= 0) t2 = 4 + t2;
if (t1 == y)
cout << "ccw";
else if (t2 == y)
cout << "cw";
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 | #include <bits/stdc++.h>
using namespace std;
map<char, int> m;
int main() {
char ch, ch1;
cin >> ch >> ch1;
int n;
cin >> n;
if (ch == '^') {
m['^'] = 0;
m['>'] = 1;
m['v'] = 2;
m['<'] = 3;
} else if (ch == '>') {
m['>'] = 0;
m['v'] = 1;
m['<'] = 2;
m['^'] = 3;
} else if (ch == 'v') {
m['v'] = 0;
m['<'] = 1;
m['^'] = 2;
m['>'] = 3;
} else if (ch == '<') {
m['<'] = 0;
m['^'] = 1;
m['>'] = 2;
m['v'] = 3;
}
n = n % 4;
if (n == 0 || n == 2)
printf("undefined\n");
else if (n == m[ch1]) {
printf("cw\n");
} else if (4 - n == m[ch1])
printf("ccw\n");
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | 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 AEroui
*/
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 {
public void solve(int testNumber, Scanner in, PrintWriter out) {
char[] arr = {'v', '<', '^', '>'};
char c1 = in.next().charAt(0);
char c2 = in.next().charAt(0);
int cur = 0;
if (c1 == '^') cur = 2;
else if (c1 == '>') cur = 3;
else if (c1 == 'v') cur = 0;
else cur = 1;
int n = in.nextInt();
int cur1 = cur + n;
int cur2 = cur - n;
while (cur2 < 0) cur2 += 4;
if ((cur1 % 4) == (cur2 % 4)) out.println("undefined");
else if (c2 == arr[cur1 % 4]) out.println("cw");
else if (c2 == arr[cur2 % 4]) out.println("ccw");
else 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.io.*;
import java.util.ArrayList;
public class Main {
void solve(StreamTokenizer in, PrintWriter out) throws IOException {
BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
String[] a=r.readLine().split(" ");
int time=Integer.parseInt(r.readLine());
time=time%4;
int[] k={118,60,94,62,118,60,94,62,118,60,94,62};
if (a[0].charAt(0)==118){
if (k[4-time]==a[1].charAt(0)&&k[4+time]==a[1].charAt(0)) out.print("undefined");
else if (k[4+time]==a[1].charAt(0)) out.print("cw");
else out.print("ccw");
}
else if (a[0].charAt(0)==60){
if (k[5-time]==a[1].charAt(0)&&k[5+time]==a[1].charAt(0)) out.print("undefined");
else if (k[5+time]==a[1].charAt(0)) out.print("cw");
else out.print("ccw");
}
else if (a[0].charAt(0)==94){
if (k[6-time]==a[1].charAt(0)&&k[6+time]==a[1].charAt(0)) out.print("undefined");
else if (k[6+time]==a[1].charAt(0)) out.print("cw");
else out.print("ccw");;
}
else if (a[0].charAt(0)==62){
if (k[7-time]==a[1].charAt(0)&&k[7+time]==a[1].charAt(0)) out.print("undefined");
else if (k[7+time]==a[1].charAt(0)) out.print("cw");
else out.print("ccw");
}
}
StreamTokenizer in;
PrintWriter out;
int nextInt() throws IOException
{
in.nextToken();
return (int)in.nval;
}
long nextLong() throws IOException
{
in.nextToken();
return (long)in.nval;
}
double nextDouble() throws IOException
{
in.nextToken();
return in.nval;
}
void run() throws IOException {
in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
out =new PrintWriter(System.out);
solve(in,out);
out.flush();
}
public static void main(String[] args)throws IOException {
// write your code here
new Main().run();
}
} | 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 | cw = "<^>v"
ccw = "<v>^"
start, end = input().split()
time = int(input())
last_turns = time % 4
cw_end_pos = (cw.index(start) + last_turns) % 4
ccw_end_pos = (ccw.index(start) + last_turns) % 4
if cw[cw_end_pos] == ccw[ccw_end_pos]:
print("undefined")
elif cw[cw_end_pos] == end:
print("cw")
else:
print("ccw")
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k, x, yc;
char a, b;
cin >> a >> b >> n;
n = n % 4;
if (n % 2 == 0)
cout << "undefined";
else if (n == 1)
if (((a == '>') and (b == 'v')) or ((a == 'v') and (b == '<')) or
((a == '<') and (b == '^')) or ((a == '^') and (b == '>')))
cout << "cw";
else
cout << "ccw";
else if (((a == '>') and (b == '^')) or ((a == 'v') and (b == '>')) or
((a == '<') and (b == 'v')) or ((a == '^') and (b == '<')))
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 | #include <bits/stdc++.h>
using namespace std;
int n;
char a[3], b[3];
int getNum(char *str) {
if (str[0] == '^')
return 0;
else if (str[0] == '>')
return 1;
else if (str[0] == 'v')
return 2;
else
return 3;
}
int main() {
while (~scanf("%s%s", a, b)) {
int t;
scanf("%d", &t);
t %= 4;
int d1 = getNum(a);
int d2 = getNum(b);
int d = d1 - d2;
if (abs(d) == 2 || d == 0)
printf("undefined\n");
else if ((d + 4) % 4 == t)
printf("ccw\n");
else if ((4 - d) % 4 == t)
printf("cw\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 | #include <bits/stdc++.h>
using namespace std;
int n, a[4] = {118, 60, 94, 62}, ac1, ac2;
int main() {
char c1, c2;
cin >> c1 >> c2;
cin >> n;
for (int i = 0; i < 4; i++) {
if ((int)c1 == a[i]) ac1 = i;
if ((int)c2 == a[i]) ac2 = i;
}
if ((ac1 + n) % 4 == ac2 && (((ac1 - n) % 4) + 4) % 4 == ac2)
cout << "undefined" << endl;
else if ((ac1 + n) % 4 == ac2)
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 | a = ['v', '<', '^', '>']
k = map(str, raw_input().split())
n = int(raw_input())
p = n+ a.index(k[0])
q = a.index(k[0]) - n
p=p%4
q=q%4
if(a[p]==k[1] and a[q]==k[1]):
print 'undefined'
elif(a[p]==k[1]):
print "cw"
else:
print "ccw"
| PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.io.*;
import java.util.*;
public class A {
public A() {
Scanner s = new Scanner();
char start = s.next().charAt(0);
char end = s.next().charAt(0);
int count = s.nextInt();
if (count % 2 == 0 || count % 2 == 0) {
System.out.println("undefined");
}
else {
for (int i = 0; i < count % 4; i++) {
start = cwn(start);
}
if (start == end) {
System.out.println("cw");
}
else {
System.out.println("ccw");
}
}
}
public char cwn(char c) {
if (c == 'v') {
return '<';
}
if (c == '^') {
return '>';
}
if(c == '>') {
return 'v';
}
if( c == '<') {
return '^';
}return 'x';
}
public static void main(String[] args) {
new A();
}
public static class Scanner {
BufferedReader br;
StringTokenizer st;
public Scanner(Reader in) {
br = new BufferedReader(in);
}
public Scanner() {
this(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 readNextLine() {
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 | dict = {'v': 0, '<': 1, '^': 2, '>': 3}
i, j = input().split()
num = int(input())
l = dict[i]
r = dict[j]
s = r-l % 4
num = num % 4
sf = 4-s if s>0 else -s
s = 4+s if s<0 else s
if s == 0 or abs(s) == 2:
print("undefined")
elif num == sf:
print("ccw")
elif num == s:
print("cw") | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const long base = 1e9 + 7;
const long esp = 1e-10;
const int maxn = 1 * 1e5 + 1;
const double pi = atan(1) * 4;
inline long long gcd(long long a, long long b) {
long long r;
while (b) {
r = a % b;
a = b;
b = r;
}
return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
char cw[4] = {'^', '>', 'v', '<'};
char ccw[4] = {'^', '<', 'v', '>'};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
char s, t;
int n;
bool flagcw = false, flagccw = false;
cin >> s >> t;
cin >> n;
if (n == 0 and (s != t)) {
cout << "undefined";
return 0;
}
for (int i = 0; i < 4; i++) {
if (cw[i] == s) {
int tmp = (i + 1 + n) % 4 - 1;
if (tmp == -1) tmp = 3;
if (cw[tmp] == t) {
flagcw = true;
}
}
}
for (int i = 0; i < 4; i++) {
if (ccw[i] == s) {
int tmp = (i + 1 + n) % 4 - 1;
if (tmp == -1) tmp = 3;
if (ccw[tmp] == t) {
flagccw = true;
}
}
}
if ((flagccw and flagcw) or (flagccw == false and flagcw == false))
cout << "undefined";
else if (flagcw and flagccw == false)
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 | import java.io.*;
import java.lang.*;
import java.util.*;
public class Main
{
public static void main(String a[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader((System.in)));
String s1=br.readLine();
String arr[]=s1.split(" ");
char c1=(char)arr[0].charAt(0);
char c2=(char)arr[1].charAt(0);
// System.out.println(c1+" "+c2);
int l=Integer.parseInt(br.readLine());
int n1=checkclock(c1,c2,l);
int n2=checkanticlock(c1,c2,l);
if(n1==n2)
System.out.println("undefined");
else if(n1==1 && n2==0)
System.out.println("cw");
else if(n1==0 && n2==1)
System.out.println("ccw");
}
public static int checkclock(char c1,char c2,int l)
{
char c[]={'^','>','v','<'};
int index=-1;
int i;
for(i=0;i<4;i++)
{
if(c[i]==c1) {
index = i;
}
}
int k=(index+l)%4;
char p=c[k];
if(p==c2)
return 1;
else
return 0;
}
public static int checkanticlock(char c1,char c2,int l)
{
char c[]={'^','<','v','>'};
int index=-1;
int i;
for(i=0;i<4;i++)
{
if(c[i]==c1)
index=i;
}
int k=(index+l)%4;
char p=c[k];
if(p==c2)
return 1;
else
return 0;
}
} | JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
MyScanner sc = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
// Start writing your solution here. -------------------------------------
String c1 = sc.next();
String c2 = sc.next();
int n = sc.nextInt() % 4;
if (n == 0 || n == 2) {
out.println("undefined");
} else {
if (n == 1) {
if (c1.charAt(0) == '^' && c2.charAt(0) == '>' ||
c1.charAt(0) == '>' && c2.charAt(0) == 'v' ||
c1.charAt(0) == 'v' && c2.charAt(0) == '<' ||
c1.charAt(0) == '<' && c2.charAt(0) == '^') {
out.println("cw");
} else{
out.println("ccw");
}
} else {
if (c1.charAt(0) == '^' && c2.charAt(0) == '<' ||
c1.charAt(0) == '>' && c2.charAt(0) == '^' ||
c1.charAt(0) == 'v' && c2.charAt(0) == '>' ||
c1.charAt(0) == '<' && c2.charAt(0) == 'v') {
out.println("cw");
} else{
out.println("ccw");
}
}
}
/*
int n = sc.nextInt(); // read input as integer
long k = sc.nextLong(); // read input as long
double d = sc.nextDouble(); // read input as double
String str = sc.next(); // read input as String
String s = sc.nextLine(); // read whole line as String
int result = 3*n;
out.println(result); // print via PrintWriter
*/
// Stop writing your solution here. -------------------------------------
out.close();
}
//-----------PrintWriter for faster output---------------------------------
public static PrintWriter out;
//-----------MyScanner class for faster input----------
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
//--------------------------------------------------------
} | 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 a, b;
int k, A, B, x, y, z;
int v[4] = {118, 60, 94, 62};
while (cin >> a >> b >> k) {
A = (int)a;
B = (int)b;
if (A == 118) {
x = 0;
} else if (A == 60) {
x = 1;
} else if (A == 94) {
x = 2;
} else if (A == 62) {
x = 3;
}
y = (x + k) % 4;
x = x - k;
while (x < 0) x = x + 4;
z = x % 4;
if (v[y] == B and v[z] == B)
cout << "undefined\n";
else if (v[y] == B)
cout << "cw\n";
else if (v[z] == B)
cout << "ccw\n";
else
cout << "undefined\n";
}
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
long long pow(long long a, long long b, long long mod) {
stack<int> k;
int j = 2048;
int l = 1;
int an = 1;
while (b) {
if (b >= j) {
k.push(j);
b -= j;
}
j /= 2;
}
while (!k.empty()) {
if (k.top() == l) {
an = (an * a) % mod;
k.pop();
}
a = (a * a) % mod;
l *= 2;
}
return an;
}
long long an = 0;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
char x, y;
int n;
cin >> x >> y >> n;
n = n % 4;
string s;
if (x == '>') {
if (n == 1 && y == 'v' || (n == 3 && y == '^')) {
s = "cw";
} else if (n == 1 && y == '^' || (n == 3 && y == 'v')) {
s = "ccw";
} else {
s = "undefined";
}
} else if (x == '<') {
if (n == 1 && y == 'v' || (n == 3 && y == '^')) {
s = "ccw";
} else if (n == 1 && y == '^' || (n == 3 && y == 'v')) {
s = "cw";
} else {
s = "undefined";
}
} else if (x == '^') {
if (n == 1 && y == '>' || (n == 3 && y == '<')) {
s = "cw";
} else if (n == 1 && y == '<' || (n == 3 && y == '>')) {
s = "ccw";
} else {
s = "undefined";
}
} else {
if (n == 1 && y == '>' || (n == 3 && y == '<')) {
s = "ccw";
} else if (n == 1 && y == '<' || (n == 3 && y == '>')) {
s = "cw";
} else {
s = "undefined";
}
}
cout << s << 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;
int main() {
char a, b, c;
cin >> a >> b;
int n;
cin >> n;
if (a == '^') {
int mod = n % 4;
if (mod == 1) {
if (b == '>')
cout << "cw" << endl;
else if (b == '<')
cout << "ccw" << endl;
} else if (mod == 3) {
if (b == '>')
cout << "ccw" << endl;
else if (b == '<')
cout << "cw" << endl;
} else
cout << "undefined" << endl;
} else if (a == '<') {
int mod = n % 4;
if (mod == 1) {
if (b == '^')
cout << "cw" << endl;
else if (b == 'v')
cout << "ccw" << endl;
} else if (mod == 3) {
if (b == '^')
cout << "ccw" << endl;
else if (b == 'v')
cout << "cw" << endl;
} else
cout << "undefined" << endl;
}
if (a == '>') {
int mod = n % 4;
if (mod == 1) {
if (b == 'v')
cout << "cw" << endl;
else if (b == '^')
cout << "ccw" << endl;
} else if (mod == 3) {
if (b == 'v')
cout << "ccw" << endl;
else if (b == '^')
cout << "cw" << endl;
} else
cout << "undefined" << endl;
} else if (a == 'v') {
int mod = n % 4;
if (mod == 1) {
if (b == '<')
cout << "cw" << endl;
else if (b == '>')
cout << "ccw" << endl;
} else if (mod == 3) {
if (b == '<')
cout << "ccw" << endl;
else if (b == '>')
cout << "cw" << 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 |
import java.io.*;
import java.util.*;
import static java.lang.Integer.parseInt;
import java.math.BigInteger;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer tk;
// Scanner in=new Scanner(System.in);
// PrintWriter p = new PrintWriter(System.out);
StringBuilder out = new StringBuilder();
tk = new StringTokenizer(in.readLine());
boolean fcw=false,fccw=false;
char f=tk.nextToken().charAt(0),s=tk.nextToken().charAt(0);
int duration=parseInt(in.readLine());
char[]cw={'^','>','v','<'},ccw={'^','<','v','>'};
int ind=find(cw, f),ind2=find(ccw, f);
if(cw[(ind+duration)%4]==s){
fcw=true;
}
if(ccw[(ind2+duration)%4]==s)
fccw=true;
if((fccw&&fcw)||(!fccw&&!fcw)){
System.out.println("undefined");
}
else if(fcw){
System.out.println("cw");
}
else System.out.println("ccw");
}
static int find(char[]a,char x){
int i=0;
while(a[i]!=x)
i++;
return 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 | a, b = [i for i in input().split()]
n = int(input())
pos = ['v', '<', '^', '>']
i = pos.index(a)
f1 = pos[(i + n) % 4]
f2 = pos[(i - n) % 4]
if f1 == f2:
print('undefined')
elif f1 == b:
print('cw')
elif f2 == b:
print('ccw')
else:
print('undefined') | PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
char a, b;
int n;
cin >> a >> b >> n;
if (n % 2 == 0) {
cout << "undefined";
return 0;
}
if (a == 'v' && b == '^' || a == '^' && b == 'v' || a == '<' && b == '>' ||
a == '>' && b == '<') {
cout << "undefined";
return 0;
}
if (a == '^') {
if (b == '>') {
if (n % 4 == 1) {
cout << "cw";
return 0;
} else {
cout << "ccw";
return 0;
}
}
if (b == '<') {
if (n % 4 == 1) {
cout << "ccw";
return 0;
} else {
cout << "cw";
return 0;
}
}
}
if (a == '>') {
if (b == 'v') {
if (n % 4 == 1) {
cout << "cw";
return 0;
} else {
cout << "ccw";
return 0;
}
}
if (b == '^') {
if (n % 4 == 1) {
cout << "ccw";
return 0;
} else {
cout << "cw";
return 0;
}
}
}
if (a == 'v') {
if (b == '<') {
if (n % 4 == 1) {
cout << "cw";
return 0;
} else {
cout << "ccw";
return 0;
}
}
if (b == '>') {
if (n % 4 == 1) {
cout << "ccw";
return 0;
} else {
cout << "cw";
return 0;
}
}
}
if (a == '<') {
if (b == '^') {
if (n % 4 == 1) {
cout << "cw";
return 0;
} else {
cout << "ccw";
return 0;
}
}
if (b == 'v') {
if (n % 4 == 1) {
cout << "ccw";
return 0;
} else {
cout << "cw";
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 maxn = 5e5 + 100;
const int INF = 0x7fffffff;
const int dir[5][2] = {0, 0, -1, 0, 1, 0, 0, -1, 0, 1};
const long long MOD = 1e9 + 7;
char cw[10] = "v<^>";
char ccw[10] = ">^<v";
char a, b;
int n, id[150];
int getN(char s[], char c) { return strchr(s, c) - s; }
int main() {
while (scanf("%c %c", &a, &b) == 2) {
scanf("%d", &n);
getchar();
bool f1 = 0, f2 = 0;
int p = (getN(cw, a) + n) % 4;
int q = (getN(ccw, a) + n) % 4;
if (cw[p] == b) f1 = 1;
if (ccw[q] == b) f2 = 1;
if (f1 ^ f2 == 0)
printf("undefined\n");
else if (f1)
printf("cw\n");
else
printf("ccw\n");
}
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | # Fast IO Region
import os
import sys
"""
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
"""
# Get out of main function
def main():
pass
# decimal to binary
def binary(n):
return (bin(n).replace("0b", ""))
# binary to decimal
def decimal(s):
return (int(s, 2))
# power of a number base 2
def pow2(n):
p = 0
while n > 1:
n //= 2
p += 1
return (p)
# if number is prime in βn time
def isPrime(n):
if (n == 1):
return (False)
else:
root = int(n ** 0.5)
root += 1
for i in range(2, root):
if (n % i == 0):
return (False)
return (True)
# list to string ,no spaces
def lts(l):
s = ''.join(map(str, l))
return s
# String to list
def stl(s):
# for each character in string to list with no spaces -->
l = list(s)
# for space in string -->
# l=list(s.split(" "))
return l
# Returns list of numbers with a particular sum
def sq(a, target, arr=[]):
s = sum(arr)
if (s == target):
return arr
if (s >= target):
return
for i in range(len(a)):
n = a[i]
remaining = a[i + 1:]
ans = sq(remaining, target, arr + [n])
if (ans):
return ans
# Sieve for prime numbers in a range
def SieveOfEratosthenes(n):
cnt = 0
prime = [True for i in range(n + 1)]
p = 2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * p, n + 1, p):
prime[i] = False
p += 1
for p in range(2, n + 1):
if prime[p]:
cnt += 1
# print(p)
return (cnt)
# for positive integerse only
def nCr(n, r):
f = math.factorial
return f(n) // f(r) // f(n - r)
# 1000000007
mod = int(1e9) + 7
def ssinp(): return input()
# s=input()
def iinp(): return int(input())
# n=int(input())
def nninp(): return map(int, input().split())
# a,b,c=map(int,input().split())
def llinp(): return list(map(int, input().split()))
# a=list(map(int,input().split()))
def p(xyz): print(xyz)
def p2(a, b): print(a, b)
import math
# import random
# sys.setrecursionlimit(300000)
# from fractions import Fraction
from collections import OrderedDict
# from collections import deque
######################## mat=[[0 for i in range(n)] for j in range(m)] ########################
######################## list.sort(key=lambda x:x[1]) for sorting a list according to second element in sublist ########################
######################## Speed: STRING < LIST < SET,DICTIONARY ########################
######################## from collections import deque ########################
######################## ASCII of A-Z= 65-90 ########################
######################## ASCII of a-z= 97-122 ########################
######################## d1.setdefault(key, []).append(value) ########################
#for __ in range(iinp()):
start,end=map(str,input().split())
n=int(input())
mul=ord(start)*ord(end)
if(mul==118*94 or mul==60*62 or mul==118*118 or mul==94*94 or mul==60*60 or mul==62*62):
print("undefined")
else:
f=0
if(ord(end)>ord(start)):
start,end=end,start
n=n+2
nos=n%4
if(ord(start)==94):
if((ord(end)==62 and nos==1) or (ord(end)==60 and nos==3)):
print("cw")
else:
print("ccw")
else:
if((ord(end)==60 and nos==1) or(ord(end)==62 and nos==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 | def rotate_cw(n,pos):
n=n%4
if n==0:
return pos
if n==1:
return (pos+1)%4
if n==2:
return (pos+2)%4
if n==3:
return (pos+3)%4
def rotate_ccw(n,pos):
n=n%4
if n==0:
return pos
if n==1:
return (pos-1)%4
if n==2:
return (pos-2)%4
if n==3:
return (pos-3)%4
def change(c):
if ord(c)==118:
return 2
elif ord(c)==60:
return 3
elif ord(c)==94:
return 0
elif ord(c)==62:
return 1
initial,final=input().split()
n=int(input())
i=change(initial)
f=change(final)
if f==rotate_cw(n,i) and f==rotate_ccw(n,i):
print("undefined")
elif f==rotate_ccw(n,i):
print("ccw")
elif f==rotate_cw(n,i):
print("cw")
else:
print("undefined")
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | inp=input().split()
duration=int(input())%4
start=inp[0]
end=inp[1]
if start=="^":
if duration==1:
if end==">":
print("cw")
else:
print("ccw")
elif duration==3:
if end==">":
print("ccw")
else:
print("cw")
else:
print("undefined")
if start==">":
if duration==1:
if end=="v":
print("cw")
else:
print("ccw")
elif duration==3:
if end=="v":
print("ccw")
else:
print("cw")
else:
print("undefined")
if start=="v":
if duration==1:
if end=="<":
print("cw")
else:
print("ccw")
elif duration==3:
if end=="<":
print("ccw")
else:
print("cw")
else:
print("undefined")
if start=="<":
if duration==1:
if end=="^":
print("cw")
else:
print("ccw")
elif duration==3:
if end=="^":
print("ccw")
else:
print("cw")
else:
print("undefined")
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
int main() {
char arr[4] = {'v', '<', '^', '>'};
char st, fin;
int n, i, idx = 0, cnt;
scanf("%c %c %d", &st, &fin, &n);
if (n % 2 == 0) {
printf("undefined");
return 0;
}
n = n % 4;
while (arr[idx] != st) idx++;
cnt = 0;
for (i = idx; cnt <= n; i++) {
cnt++;
if (i % 4 == 0) i = 0;
}
if (i - 1 < 0) i = 3;
if (arr[i - 1] == fin) {
printf("cw");
return 0;
}
cnt = 0;
for (i = idx; cnt <= n; i--) {
cnt++;
if (i < 0) i = 3;
}
if (i + 1 > 3) i = 0;
if (arr[i + 1] == fin) {
printf("ccw");
return 0;
}
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | s = "^>v<"
a,b = input().split()
n = int(input())
a = s.index(a)
b = s.index(b)
ok1 = False
ok2 = False
#print(a,b)
if((a + n)%4 == b): ok1 = True
if((a - n)%4 == b): ok2 = True
elif((a - n)%4 + 4 == b): ok2 = True
if(ok1 and not ok2): print("cw")
elif(not ok1 and ok2): 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 |
m = {'^':0, '>':1, 'v':2, '<':3}
a,b = input().split()
n = int(input())
a,b = m[a], m[b]
cwdist = (b-a)%4
ccwdist = (a-b)%4
if cwdist == ccwdist:
print("undefined")
elif cwdist == 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 | from sys import stdin
def f(pos):
if pos == '^':
return 0
if pos == '>':
return 1
if pos == 'v':
return 2
if pos == '<':
return 3
def direction(pos1, pos2, n):
if (pos2 - pos1) % 4 == (pos1 - pos2) % 4:
return 'undefined'
if (pos2 - pos1) % 4 == n % 4:
return 'cw'
if (pos1 - pos2) % 4 == n % 4:
return 'ccw'
pos1, pos2 = stdin.readline().strip().split()
pos1, pos2 = f(pos1), f(pos2)
n = int(stdin.readline().strip())
print direction(pos1, pos2, n) | PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | a,b=input().split()
n=int(input())
n=n%4
V=['^','>','v','<']
i=0
while a!=V[i]:
i+=1
ti=(i+4-n)%4
i=(i+n)%4
if b==V[i] and b==V[ti]:
print('undefined')
elif b==V[i]:
print('cw')
elif b==V[ti]:
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 | #!/usr/bin/python
# coding: utf-8
cw=['v','<','^','>','v','<','^','>']
ccw=['v','>','^','<','v','>','^','<']
(s,e)=map(str,raw_input().split(' '))
n=int(raw_input())
n=n%4
tmp1=tmp2=0
cwind=cw.index(s)+n
ccwind=ccw.index(s)+n
if(cw[cwind]==e):
tmp1=1
if(ccw[ccwind]==e):
tmp2=1
if(tmp1==1 and tmp2==1):
print "undefined"
elif(tmp1):
print "cw"
else:
print "ccw"
| PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
void fast() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int main() {
fast();
char ch1, ch2, a[] = {'v', '<', '^', '>'};
int n, flag1 = 0, flag2 = 0, pos;
cin >> ch1 >> ch2 >> n;
n %= 4;
for (int i = 0; i < 4; i++)
if (ch1 == a[i]) pos = i;
if (ch2 == a[(pos + n) % 4]) flag1 = 1;
if (ch2 == a[pos - n < 0 ? 3 - (n - pos - 1) : pos - n]) flag2 = 1;
if (flag1 == flag2) return cout << "undefined", 0;
if (flag1)
return cout << "cw", 0;
else
return cout << "ccw", 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;
long long int power(long long int x, long long int n, long long int m) {
long long int res = 1;
while (n > 0) {
if (n & 1) res = (res * x) % m;
x = (x * x) % m;
n = n >> 1;
}
return res;
}
long long int maxSubsetSum(vector<long long int> v) {
long long int max_so_far = LLONG_MIN, max_ending_here = 0;
for (long long int i = 0; i < (long long int)v.size(); i++) {
max_ending_here += v[i];
if (max_so_far < max_ending_here) max_so_far = max_ending_here;
if (max_ending_here < 0) max_ending_here = 0;
}
return max_so_far;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
char s1, s2;
long long int n;
cin >> s1 >> s2 >> n;
n %= 4;
map<char, long long int> m;
m['v'] = 0;
m['<'] = 1;
m['^'] = 2;
m['>'] = 3;
char arr[4] = {'v', '<', '^', '>'};
if (n % 2 == 0)
cout << "undefined" << endl;
else if (arr[(m[s1] + n) % 4] == s2)
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 int INF = 0x3f3f3f3f;
int a[10], n;
char s1, s2;
int main() {
a[0] = 118, a[1] = 60, a[2] = 94, a[3] = 62;
while (cin >> s1 >> s2) {
scanf("%d", &n);
n %= 4;
int k;
for (int i = 0; i < 4; i++)
if ((int)s1 == a[i]) {
k = i;
break;
}
int kk = (k + n) % 4, kkk = ((k - n) % 4 + 4) % 4;
if (a[kk] == (int)s2 && kkk == kk)
printf("undefined\n");
else if (a[kk] == (int)s2)
printf("cw\n");
else
printf("ccw\n");
}
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int getNum(char c) {
if (c == 'v')
return 0;
else if (c == '<')
return 1;
else if (c == '^')
return 2;
else
return 3;
}
int main() {
char s, e;
cin >> s >> e;
int a = getNum(s);
int b = getNum(e);
int n;
cin >> n;
n %= 4;
if ((a + n) % 4 == b && !((a + 4 - n) % 4 == b)) {
cout << "cw" << endl;
} else if ((a + 4 - n) % 4 == b && !((a + n) % 4 == b)) {
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 | #include <bits/stdc++.h>
using namespace std;
char a, b;
int n;
int main() {
cin >> a >> b;
cin >> n;
n = n % 4;
if (n == 0 || n == 2) {
cout << "undefined" << endl;
} else {
int s, e;
if (a == 118) {
s = 0;
}
if (a == 60) {
s = 1;
}
if (a == 94) {
s = 2;
}
if (a == 62) {
s = 3;
}
if (b == 118) {
e = 0;
}
if (b == 60) {
e = 1;
}
if (b == 94) {
e = 2;
}
if (b == 62) {
e = 3;
}
int x = (e - s + 4) % 4;
if (x == n) {
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 | state=['v','<','^','>']
s,e=str(raw_input()).split()
n=int(raw_input())%4
if (n%2)==0:print 'undefined'
else:
if n==1:
if state.index(s)-state.index(e) in [-1,3]:print 'cw'
elif state.index(s)-state.index(e) in [1,-3]: print 'ccw'
else:print 'undefined'
elif n==3:
if state.index(s)-state.index(e) in [1,-3]:print 'cw'
elif state.index(s)-state.index(e) in [-1,3]: print 'ccw'
else:print 'undefined' | PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.util.*;
import java.io.*;
public class R426_A {
FastScanner in;
PrintWriter out;
public void solve() {
String s = in.next();
String f = in.next();
int a = -1;
int b = -1;
if (s.compareTo("^") == 0) {
a = 4;
}
if (s.compareTo(">") == 0) {
a = 5;
}
if (s.compareTo("v") == 0) {
a = 6;
}
if (s.compareTo("<") == 0) {
a = 7;
}
if (f.compareTo("^") == 0) {
b = 4;
}
if (f.compareTo(">") == 0) {
b = 5;
}
if (f.compareTo("v") == 0) {
b = 6;
}
if (f.compareTo("<") == 0) {
b = 7;
}
int n = in.nextInt();
n %= 4;
switch (n) {
case 0: {
out.println("undefined");
return;
}
case 1: {
if ((a - b == 1) || (a - b == -3)) {
out.println("ccw");
} else {
out.println("cw");
}
return;
}
case 2: {
out.println("undefined");
return;
}
case 3: {
if ((a - b == 1) || (a - b == -3)) {
out.println("cw");
} else {
out.println("ccw");
}
return;
}
}
}
public void run() {
in = new FastScanner();
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
solve();
out.close();
}
class FastScanner {
StringTokenizer st;
BufferedReader br;
FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreTokens()) {
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());
}
}
public static void main(String[] args) {
new R426_A().run();
}
}
| 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.Scanner;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
uselesstoy solver = new uselesstoy();
solver.solve(1, in, out);
out.close();
}
static class uselesstoy {
String s;
char begin;
char end;
long num;
public void solve(int testNumber, Scanner in, PrintWriter out) {
s = in.next();
begin = s.charAt(0);
s = in.next();
end = s.charAt(0);
num = in.nextLong();
if (num % 2 == 0) out.println("undefined");
else {
if (begin == 'v') {
if (end == '<') {
if (num % 4 == 1) out.println("cw");
else out.println("ccw");
} else {
if (num % 4 == 3) out.println("cw");
else out.println("ccw");
}
} else if (begin == '<') {
if (end == '^') {
if (num % 4 == 1) out.println("cw");
else out.println("ccw");
} else {
if (num % 4 == 3) out.println("cw");
else out.println("ccw");
}
} else if (begin == '^') {
if (end == '>') {
if (num % 4 == 1) out.println("cw");
else out.println("ccw");
} else {
if (num % 4 == 3) out.println("cw");
else out.println("ccw");
}
} else if (begin == '>') {
if (end == 'v') {
if (num % 4 == 1) out.println("cw");
else out.println("ccw");
} else {
if (num % 4 == 3) out.println("cw");
else 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 | R = lambda:map(int,raw_input().split())
a = [118,60,94,62]
s = raw_input().split()
sp,ep = 0,0
for i in xrange(len(a)):
if a[i]==ord(s[0]):
sp=i
elif a[i]==ord(s[1]):
ep=i
n = R()[0]
tsp=sp
fc,fcc = False,False
tsp += n
tsp %= len(a)
if tsp == ep:
fc = True
tsp=sp
tsp -= n
tsp %= len(a)
if tsp == ep:
fcc = True
if fc==fcc:
print "undefined"
else:
if fc: 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 | s = input()
n = int(input()) % 4
if n == 0 or n == 2:
print ('undefined')
elif n == 1:
if s in ('^ >', '> v', 'v <', '< ^'):
print ('cw')
else:
print ('ccw')
else:
if s in ('^ >', '> v', 'v <', '< ^'):
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 | s, f = map(str, input().split())
n = int(input())
cw, ccw = ['^', '>', 'v', '<'], ['^', '<', 'v', '>']
cwp, ccwp = cw[(cw.index(s) + n) % 4], ccw[(ccw.index(s) + n) % 4]
print("undefined" if cwp == ccwp or cwp != f and ccwp != f else ("cw" if cwp == f 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 |
import java.util.*;
public class Main {
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
int initial, ffinal;
initial = getPos(input.next().charAt(0));
ffinal = getPos(input.next().charAt(0));
int n = input.nextInt();
if ((initial + n) % 4 == ffinal && initial != (ffinal + n) % 4) {
System.out.println("cw");
} else if ((initial + n) % 4 != ffinal && initial == (ffinal + n) % 4) {
System.out.println("ccw");
} else {
System.out.println("undefined");
}
input.close();
}
static int getPos(char shape) {
switch (shape) {
case 'v':
return 0;
case '<':
return 1;
case '^':
return 2;
default:
return 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 | l=list(map(str,input().strip().split(' ')))
#print(l)
#print(int(input()))
x=int(input())%4
a=l[0]
b=l[1]
l1=['<','^','>','v']
l2=['<','v','>','^']
i1=l1.index(a)
i2=l2.index(a)
if l1[(i1+x)%4]==b and l2[(i2+x)%4]!=b:
print("cw")
elif l2[(i2+x)%4]==b and l1[(i1+x)%4]!=b:
print("ccw")
else:
print("undefined")
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | /**
* Created by z002rgw on 7/30/17.
*/
import java.util.*;
public class TaskA {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String input = in.nextLine();
char first1 = input.charAt(0);
char second = input.charAt(2);
//System.out.println(first1 + " " + second);
Map<Character, Integer> map = new HashMap<Character, Integer>();
Map<Integer, Character> rev = new HashMap< Integer, Character>();
map.put('^', 0);
map.put('>', 1);
map.put('v', 2);
map.put('<', 3);
rev.put(0, '^');
rev.put(1, '>');
rev.put(2, 'v');
rev.put(3, '<');
int time = in.nextInt();
int first = map.get(first1);
int last = map.get(second);
if(time % 2 == 0){
System.out.println("undefined");
return;
}
time = time % 4;
first += time;
first = first % 4;
if(rev.get(first) == second) {
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 | string = input()
s = string[0]
a = string[2]
n = int(input())
b = n%4
if s == '>':
if a == '^':
if b == 1:
print("ccw")
else:
print("cw")
elif a =='v':
if b == 3:
print("ccw")
else:
print("cw")
else:
print("undefined")
elif s == '<':
if a == '^':
if b == 1:
print("cw")
else:
print("ccw")
elif a =='v':
if b == 3:
print("cw")
else:
print("ccw")
else:
print("undefined")
elif s == '^':
if a == '>':
if b == 1:
print("cw")
else:
print("ccw")
elif a =='<':
if b == 3:
print("cw")
else:
print("ccw")
else:
print("undefined")
else:
if a == '>':
if b == 1:
print("ccw")
else:
print("cw")
elif a =='<':
if b == 3:
print("ccw")
else:
print("cw")
else:
print("undefined")
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | [start, end] = raw_input().strip().split(' ')
li = ['v','<','^','>']
li2 = ['v','>','^','<']
si = li.index(start)
si2 = li2.index(start)
ei = li.index(end)
n = input()
n = n%4
answer = 0
for i in range(n):
si = (si +1)%4
si2 = (si2 +1)%4
flag1 = 0
flag2 = 0
if end == li[si]:
flag1 = 1
if end == li2[si2]:
flag2 = 1
if flag1 == 0 and flag2 == 0:
print "undefined"
elif flag1 == 1 and flag2 == 1:
print "undefined"
elif flag1 == 1:
print "cw"
else:
print "ccw"
| PYTHON |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.FileNotFoundException;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author AsgarJ
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
FastWriter out = new FastWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
static class TaskA {
public void solve(int testNumber, InputReader in, FastWriter out) {
char f = in.next().charAt(0);
char s = in.next().charAt(0);
int start = getChar(f);
int end = getChar(s);
int n = in.nextInt();
int r = n % 4;
if (r == 2 || r == 0) {
out.println("undefined");
} else if (r == (end - start + 4) % 4) {
out.println("cw");
} else {
out.println("ccw");
}
}
private int getChar(char f) {
switch (f) {
case '^':
return 1;
case '>':
return 2;
case 'v':
return 3;
case '<':
return 4;
}
return 0;
}
}
static class FastWriter extends PrintWriter {
public FastWriter(OutputStream outputStream) {
super(outputStream);
}
public FastWriter(Writer writer) {
super(writer);
}
public FastWriter(String filename) throws FileNotFoundException {
super(filename);
}
}
static class InputReader extends BufferedReader {
StringTokenizer tokenizer;
public InputReader(InputStream inputStream) {
super(new InputStreamReader(inputStream), 32768);
}
public InputReader(String filename) {
super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(readLine());
} catch (IOException e) {
throw new RuntimeException();
}
}
return tokenizer.nextToken();
}
public Integer nextInt() {
return Integer.valueOf(next());
}
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
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, x, y, dist1, dist2;
char ch[3], a;
ch[0] = getchar();
a = getchar();
ch[2] = getchar();
cin >> n;
n = n % 4;
if (n == 1 &&
((ch[0] == '^' && ch[2] == '>') || (ch[0] == '>' && ch[2] == 'v') ||
(ch[0] == 'v' && ch[2] == '<') || (ch[0] == '<' && ch[2] == '^')))
cout << "cw";
else if (n == 1 &&
((ch[0] == '^' && ch[2] == '<') || (ch[0] == '<' && ch[2] == 'v') ||
(ch[0] == 'v' && ch[2] == '>') || (ch[0] == '>' && ch[2] == '^')))
cout << "ccw";
else if (n == 3 &&
((ch[0] == '^' && ch[2] == '<') || (ch[0] == '>' && ch[2] == '^') ||
(ch[0] == 'v' && ch[2] == '>') || (ch[0] == '<' && ch[2] == 'v')))
cout << "cw";
else if (n == 3 &&
((ch[0] == '^' && ch[2] == '>') || (ch[0] == '<' && ch[2] == '^') ||
(ch[0] == 'v' && ch[2] == '<') || (ch[0] == '>' && ch[2] == 'v')))
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 | #include <bits/stdc++.h>
using namespace std;
int main() {
char ch1, ch2;
int n;
cin >> ch1 >> ch2 >> n;
if (n % 2 == 0) {
cout << "undefined";
return 0;
}
n = n % 4;
if (n == 1) {
if (ch1 == 'v' && ch2 == '<') {
cout << "cw";
return 0;
}
if (ch1 == '<' && ch2 == '^') {
cout << "cw";
return 0;
}
if (ch1 == '^' && ch2 == '>') {
cout << "cw";
return 0;
}
if (ch1 == '>' && ch2 == 'v') {
cout << "cw";
return 0;
}
if (ch1 == '<' && ch2 == 'v') {
cout << "ccw";
return 0;
}
if (ch1 == '^' && ch2 == '<') {
cout << "ccw";
return 0;
}
if (ch1 == '>' && ch2 == '^') {
cout << "ccw";
return 0;
}
if (ch1 == 'v' && ch2 == '>') {
cout << "ccw";
return 0;
}
} else {
if (ch1 == 'v' && ch2 == '<') {
cout << "ccw";
return 0;
}
if (ch1 == '<' && ch2 == '^') {
cout << "ccw";
return 0;
}
if (ch1 == '^' && ch2 == '>') {
cout << "ccw";
return 0;
}
if (ch1 == '>' && ch2 == 'v') {
cout << "ccw";
return 0;
}
if (ch1 == '<' && ch2 == 'v') {
cout << "cw";
return 0;
}
if (ch1 == '^' && ch2 == '<') {
cout << "cw";
return 0;
}
if (ch1 == '>' && ch2 == '^') {
cout << "cw";
return 0;
}
if (ch1 == 'v' && ch2 == '>') {
cout << "cw";
return 0;
}
}
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
getline(cin, s);
long long int n, f = 0, f1 = 0, f2 = 0, f3 = 0;
cin >> n;
map<long long int, long long int> clock, anti;
clock = {{'^', 0}, {'>', 0}, {'v', 0}, {'<', 0}};
anti = {{'^', 0}, {'>', 0}, {'v', 0}, {'<', 0}};
if (s[0] == '^') f = 1;
if (s[0] == '>') f1 = 1;
if (s[0] == 'v') f2 = 1;
if (s[0] == '<') f3 = 1;
long long int no = 1;
for (long long int i = 1; i < 5; i++) {
if (f == 1) {
clock['^'] = no;
no++;
f1 = 1;
f = 0;
continue;
}
if (f1 == 1) {
clock['>'] = no;
no++;
f2 = 1;
f1 = 0;
continue;
}
if (f2 == 1) {
clock['v'] = no;
no++;
f3 = 1;
f2 = 0;
continue;
}
if (f3 == 1) {
clock['<'] = no;
no++;
f3 = 1;
f = 1;
}
}
f = f1 = f2 = f3 = 0, no = 1;
if (s[0] == '^') f = 1;
if (s[0] == '<') f1 = 1;
if (s[0] == 'v') f2 = 1;
if (s[0] == '>') f3 = 1;
for (long long int i = 1; i < 5; i++) {
if (f == 1) {
anti['^'] = no;
no++;
f1 = 1;
f = 0;
continue;
}
if (f1 == 1) {
anti['<'] = no;
no++;
f2 = 1;
f1 = 0;
continue;
}
if (f2 == 1) {
anti['v'] = no;
no++;
f3 = 1;
f2 = 0;
continue;
}
if (f3 == 1) {
anti['>'] = no;
no++;
f3 = 0;
f = 1;
}
}
if (n <= 4) {
if (clock[s[2]] == anti[s[2]] && clock[s[2]] == n + 1) {
cout << "undefined";
return 0;
}
if (clock[s[2]] == n + 1) {
cout << "cw";
return 0;
}
if (anti[s[2]] == n + 1) {
cout << "ccw";
return 0;
}
cout << "undefined";
return 0;
}
if (double((n + 1) - clock[s[2]]) / 4 == double((n + 1) - anti[s[2]]) / 4) {
cout << "undefined";
return 0;
}
if (ceil((double((n + 1) - clock[s[2]]) / 4) + 1) ==
floor((double((n + 1) - clock[s[2]]) / 4) + 1)) {
cout << "cw";
return 0;
}
if (ceil((double((n + 1) - anti[s[2]]) / 4) + 1) ==
floor((double((n + 1) - anti[s[2]]) / 4) + 1)) {
cout << "ccw";
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 | #include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
std::ios::sync_with_stdio(false);
char a, b;
long long int n;
cin >> a >> b >> n;
if (n % 4 == 3) {
if ((a == 'v' && b == '>') || (a == '<' && b == 'v') ||
(a == '^' && b == '<') || (a == '>' && b == '^'))
cout << "cw\n";
else
cout << "ccw\n";
} else if (n % 4 == 1) {
if ((a == 'v' && b == '<') || (a == '<' && b == '^') ||
(a == '^' && b == '>') || (a == '>' && b == 'v'))
cout << "cw\n";
else
cout << "ccw\n";
} else
cout << "undefined\n";
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | import java.util.Scanner;
public class C426A {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String start = scanner.next();
int st;
String end = scanner.next();
int en;
int seconds = scanner.nextInt();
switch (start) {
case "^":
st = 0;
break;
case ">":
st = 1;
break;
case "v":
st = 2;
break;
default:
st = 3;
break;
}
switch (end) {
case "^":
en = 0;
break;
case ">":
en = 1;
break;
case "v":
en = 2;
break;
default:
en = 3;
break;
}
int enC = (st + seconds) % 4;
int enCC = (((st - seconds) % 4) + 4) % 4;
if (enC == en && !(enCC == en)) System.out.println("cw");
else if (enCC == en && !(enC == en)) 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 | #include <bits/stdc++.h>
using namespace std;
int inf = 1000000005;
long long int llinf = 2000000000000000005LL;
long long int mod = 1000000007;
long long int mod9 = 1000000009;
double pi = 3.1415926535897;
double eps = 1e-15;
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1}, dy[] = {0, 0, 1, -1, 1, 1, -1, -1};
vector<bool> isprime;
vector<int> primes;
void seive(int n, bool wantlist = true) {
isprime.resize(n + 1, true);
isprime[0] = isprime[1] = false;
int sq = sqrt(n + 1);
for (int i = (2); i < (sq + 1); i++) {
if (isprime[i]) {
for (int j = i * i; j <= n; j += i) isprime[j] = false;
}
}
for (int i = 2; wantlist && i <= n; i++) {
if (isprime[i]) primes.push_back(i);
}
}
template <class T>
inline T gcd(T a, T b) {
while (b > 0) {
a %= b;
swap(a, b);
}
return a;
}
template <class T>
inline T lcm(T a, T b) {
return a * b / gcd(a, b);
}
template <class T>
inline vector<T> operator+(vector<T>& a, vector<T>& b) {
assert(a.size() == b.size());
int n = a.size();
vector<T> c(n);
for (int i = 0; i < n; i++) c[i] = a[i] + b[i];
return c;
}
int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; }
inline long long int bexp(long long int x, long long int n,
long long int m = mod) {
long long int res = 1;
x %= m;
while (n) {
if (n & 1) res = res * x % m;
x = x * x % m;
n >>= 1;
}
return res;
}
inline bool ispalin(string& str) {
int n = str.length();
for (int i = 0; i < n / 2; i++)
if (str[i] != str[n - i - 1]) return false;
return true;
}
int main() {
char c1, c2;
cin >> c1 >> c2;
int n;
cin >> n;
n %= 4;
map<char, char> cw;
cw['<'] = '^';
cw['^'] = '>';
cw['>'] = 'v';
cw['v'] = '<';
if (n % 2 == 0) {
cout << "undefined" << endl;
return 0;
}
while (n--) c1 = cw[c1];
if (c2 == c1)
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 | #include <bits/stdc++.h>
using namespace std;
char rotate_cw(char curr) {
if (curr == 'v') {
return '<';
} else if (curr == '<') {
return '^';
} else if (curr == '^') {
return '>';
}
return 'v';
}
char rotate_ccw(char curr) {
if (curr == 'v') {
return '>';
} else if (curr == '<') {
return 'v';
} else if (curr == '^') {
return '<';
}
return '^';
}
int main() {
char start;
char end;
cin >> start >> end;
int time;
cin >> time;
time %= 4;
char curr_pos_cw = start;
for (int i = 0; i < time; ++i) {
curr_pos_cw = rotate_cw(curr_pos_cw);
}
char curr_pos_ccw = start;
for (int i = 0; i < time; ++i) {
curr_pos_ccw = rotate_ccw(curr_pos_ccw);
}
if (curr_pos_cw == end) {
if (curr_pos_ccw == end) {
cout << "undefined" << endl;
} else {
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 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
char s1, s2;
cin >> s1 >> s2;
int n;
cin >> n;
n %= 4;
if (n == 2 || n == 0) {
cout << "undefined" << endl;
return 0;
}
char mine[4];
mine[0] = '<';
mine[1] = '^';
mine[2] = '>';
mine[3] = 'v';
for (int i = 0; i < 4; i++) {
if (mine[i] == s1) {
if (mine[(i + n) % 4] == s2) {
cout << "cw" << endl;
return 0;
}
break;
}
}
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 | a,b=input().split()
n=int(input())
d={'^':0,'>':1,'v':2,'<':3}
e={'^':0,'>':3,'v':2,'<':1}
f1=f2=0
if (d[a]+n)%4==d[b]:
f1=1
if (e[a]+n)%4==e[b]:
f2=1
if f1 and f2:
print('undefined')
else:
print('cw' if f1 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 | import java.util.*;
public class A {
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 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
def main():
iterator = iter(sys.stdin.read().split())
a = next(iterator)
b = next(iterator)
n = int(next(iterator))
n %= 4
s = 'v<^>'
p1 = s.find(a)
p2 = s.find(b)
if (p2 - p1) % 4 == n and (p1 - p2) % 4 == n:
print('undefined')
elif (p2 - p1) % 4 == n:
print('cw')
elif (p1 - p2) % 4 == n:
print('ccw')
else:
print('undefined')
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 | #include <bits/stdc++.h>
using namespace std;
int main() {
char c1, c2;
int n;
cin >> c1 >> c2 >> n;
n %= 4;
map<char, int> mp;
mp['^'] = 0;
mp['>'] = 1;
mp['v'] = 2;
mp['<'] = 3;
int x = mp[c1], y = mp[c2];
if ((x + n) % 4 == y && (x - n + 4) % 4 != y)
cout << "cw" << endl;
else if ((x + n) % 4 != y && (x - n + 4) % 4 == y)
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 | #include <bits/stdc++.h>
using namespace std;
int ctor(char n) {
switch (n) {
case '^':
return 0;
case '>':
return 1;
case 'v':
return 2;
case '<':
return 3;
}
}
int main() {
ios_base::sync_with_stdio(false);
string a, b;
int t;
cin >> a >> b >> t;
t %= 4;
if (t == 0 || t == 2) {
cout << "undefined" << endl;
} else if (t == 1) {
if (ctor(a[0]) == (ctor(b[0]) + 1) % 4) {
cout << "ccw" << endl;
} else {
cout << "cw" << endl;
}
} else if (t == 3) {
if (ctor(a[0]) == (ctor(b[0]) + 1) % 4) {
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 | a,b = input().split()
a = ord(a)
b = ord(b)
n = int(input())
temp = n//4;
n = n % 4;
if a == 118:
if b == 118:
print("undefined")
elif b == 60:
if n == 1:
print("cw")
elif n == 3:
print("ccw")
elif b == 94:
if n == 2:
print("undefined")
elif b == 62:
if n == 1:
print("ccw")
elif n == 3:
print("cw")
elif a == 60:
if b == 118:
if n == 1:
print("ccw")
elif n == 3:
print("cw")
elif b == 60:
print("undefined")
elif b == 94:
if n == 1:
print("cw")
elif n == 3:
print("ccw")
elif b == 62:
if n == 2:
print("undefined")
elif a == 94:
if b == 118:
if n == 2:
print("undefined")
elif b == 60:
if n == 1:
print("ccw")
elif n == 3:
print("cw")
elif b == 94:
if n == 0:
print("undefined")
elif b == 62:
if n == 1:
print("cw")
elif n == 3:
print("ccw")
elif a == 62:
if b == 118:
if n == 1:
print("cw")
elif n == 3:
print("ccw")
elif b == 60:
if n == 2:
print("undefined")
elif b == 94:
if n == 1:
print("ccw")
elif n == 3:
print("cw")
elif b == 62:
if n == 0:
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 | ###modular exponentiation: a^n % M
#pow(a, n, M)
### gcd: gcd(a, b)
#import fractions
#fractions.gcd(a, b)
### LCM (M, N)
#lcm = M*N/fractions.gcd(M, N)
def get_res(start, end, r):
result = 'undefined'
Dcw = {'v':0, '<':1,'^':2, '>':3}
Dccw = {'v':0, '>':1, '^':2, '<':3}
x = r%4
a1 = Dcw[start]
a2 = Dcw[end]
if a1 > a2:
cw = (4-a1+a2)
else:
cw = a2-a1
b1 = Dccw[start]
b2 = Dccw[end]
if b1 > b2:
ccw = (4-b1+b2)
else:
ccw = b2-b1
if x == cw and x == ccw:
result= 'undefined'
elif x == cw:
result = 'cw'
elif x == ccw:
result = 'ccw'
else:
result = 'undefined'
return result
#N = int(raw_input())
start, end = [s for s in raw_input().split(" ")]
r = int(raw_input())
result = get_res(start, end, r)
print "{}".format(result)
| 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 | first,final=input().split()
n=int(input())%4
cw=first
cww=first
if n==0:
print("undefined")
else:
for _ in range(n):
if cw == "^":
cw = ">"
elif cw == ">":
cw = "v"
elif cw == "v":
cw = "<"
else:
cw = "^"
if cww == "^":
cww = "<"
elif cww == "<":
cww = "v"
elif cww == "v":
cww = ">"
else:
cww = "^"
if cw==cww:
print("undefined")
elif final==cw:
print("cw")
elif final == cww:
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.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
static class TaskA {
public void solve(int testNumber, InputReader in, PrintWriter out) {
String s1 = in.next();
int id1 = -1;
if (s1.equals("<"))
id1 = 3;
else if (s1.equals("^"))
id1 = 0;
else if (s1.equals(">"))
id1 = 1;
else if (s1.equals("v"))
id1 = 2;
String s2 = in.next();
int id2 = -1;
if (s2.equals("<"))
id2 = 3;
else if (s2.equals("^"))
id2 = 0;
else if (s2.equals(">"))
id2 = 1;
else if (s2.equals("v"))
id2 = 2;
int n = in.nextInt() % 4;
if (n == 2 || n == 0) {
out.println("undefined");
} else if (n == 1) {
if ((id1 + 1) % 4 == id2)
out.println("cw");
else
out.println("ccw");
} else if (n == 3) {
if ((id2 + 1) % 4 == id1)
out.println("cw");
else
out.println("ccw");
}
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[16384];
private int curChar;
private int numChars;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String next() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public int nextInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
private boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | a=input()
n=int(input())
d={}
ans={}
d['^']=1
d['>']=2
d['v']=3
d['<']=0
ans[2]='>'
ans[1]='^'
ans[0]='<'
ans[3]='v'
count=d[a[0]]
count+=n
count=count%4
se=d[a[2]]
se+=n
se=se%4
if (ans[count]==a[2] and ans[se]==a[0]) or (ans[se]!=a[0] and ans[count]!=a[2]):
print("undefined")
elif ans[count]==a[2]:
print('cw')
elif ans[se]==a[0]:
print('ccw')
| PYTHON3 |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
char arr[4], a, b;
arr[0] = 118;
arr[1] = 60;
arr[2] = 94;
arr[3] = 62;
cin >> a >> b;
int i, j, n;
cin >> n;
for (i = 0; i < 4; i++) {
if (a == arr[i]) break;
}
for (j = 0; j < 4; j++) {
if (b == arr[j]) break;
}
if (arr[(i + n) % 4] == arr[j] && arr[(j + n) % 4] == arr[i]) {
cout << "undefined";
return 0;
}
if (arr[(i + n) % 4] == arr[j]) {
cout << "cw";
return 0;
}
if (arr[(j + n) % 4] == arr[i]) {
cout << "ccw";
return 0;
}
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 | #include <bits/stdc++.h>
using namespace std;
unsigned int test(char x) {
if (x == 'v') {
return 0;
}
if (x == '<') {
return 1;
}
if (x == '^') {
return 2;
}
if (x == '>') {
return 3;
}
return -1;
}
int main(int argc, char const *argv[]) {
char i, o;
int pos_i, pos_o, ass_c, ass_a, t;
scanf("%c %c %d", &i, &o, &t);
pos_i = test(i);
pos_o = test(o);
ass_c = (pos_i + t) % 4;
ass_a = (pos_i + 1000000000 - t) % 4;
if ((ass_a == pos_o) && (ass_c == pos_o)) {
printf("undefined\n");
} else if (ass_c == pos_o) {
printf("cw\n");
} else if (ass_a == pos_o) {
printf("ccw\n");
}
return 0;
}
| CPP |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
char c[2];
int t, b[2];
cin >> c[0] >> c[1];
cin >> t;
std::map<char, int> make_pair;
make_pair['^'] = 0;
make_pair['>'] = 1;
make_pair['v'] = 2;
make_pair['<'] = 3;
bool x = (make_pair[c[0]] + t) % 4 == make_pair[c[1]];
bool y = (make_pair[c[0]] - (t % 4) + 4) % 4 == make_pair[c[1]];
if (x && y)
puts("undefined");
else if (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 | import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class _0549TheUselessToy {
public static void main(String[] args) {
// System.out.println((start+1)%(end-start));
Scanner sc = new Scanner(System.in);
String start=sc.next();
String end=sc.next();
int n=sc.nextInt();
Map<String,Integer> store = new HashMap<>();
store.put("^",0);
store.put(">",1);
store.put("v",2);
store.put("<",3);
String combine=end+start;
if(combine.contains("^")&& combine.contains("v")||(combine.contains("<")&& combine.contains(">")) && n%4!=0 && n%2==0) {
System.out.println("undefined");
return;
}
else if(start.equals(end) && n%4==0) {
System.out.println("undefined");
return;
}
else {
n=n%4;
int init=store.get(start);
int last=store.get(end);
int forward=(init+n)%4;
if(last ==forward) {
System.out.println("cw");
}
else {
System.out.println("ccw");
}
}
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
char a, b;
scanf("%c %c\n", &a, &b);
int n;
scanf("%d", &n);
n %= 4;
if (a == b) {
printf("undefined\n");
return 0;
}
bool cw = 0, ccw = 0;
char c[10] = {118, 60, 94, 62, 118, 60, 94, 62};
char c1[10] = {62, 94, 60, 118, 62, 94, 60, 118};
int start = 0, end = 0;
for (int i = 0; i < 5; i++) {
start = i;
if (c[i] == a) break;
}
for (int j = start + 1; j < 10; j++) {
end = j;
if (c[j] == b) break;
}
if (end - start == n) {
cw = 1;
}
start = 0, end = 0;
for (int i = 0; i < 5; i++) {
start = i;
if (c1[i] == a) break;
}
for (int j = start + 1; j < 10; j++) {
end = j;
if (c1[j] == b) break;
}
if (end - start == n) ccw = 1;
if ((cw and ccw) or (!cw and !ccw))
printf("undefined\n");
else if (cw)
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 | import java.lang.reflect.Array;
import java.util.Scanner;
import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
import static java.lang.Math.*;
public class main implements Runnable {
static ArrayList<Integer> adj[];
static void Check2(int n) {
adj = new ArrayList[n + 1];
for (int i = 0; i <= n; i++) {
adj[i] = new ArrayList<>();
}
}
static void add(int i, int j) {
adj[i].add(j);
}
public static void main(String[] args) {
new Thread(null, new main(), "Check2", 1 << 26).start();// to increse stack size in java
}
static long mod = (long) (1e9 + 7);
public void run() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
//Scanner in=new Scanner(System.in);
InputReader in = new InputReader(System.in);
PrintWriter w = new PrintWriter(System.out);
char c=in.next().charAt(0);
char d=in.next().charAt(0);
long n=in.nextLong();
char e[]=new char[4];
e[0]=118;
e[1]=60;
e[2]=94;
e[3]=62;
int i=0;
int j=0;
for(int k=0;k<4;k++){
if(e[k]==c){
i=k;
// break;
}
if(e[k]==d){
j=k;
}
}
if(i<j){
int val=j-i;
int val2=4-val;
if((n-val+4)%4==0&&(n-val2+4)%4!=0){
w.println("cw");
}
else if((n-val2+4)%4==0&&(n-val+4)%4!=0){
w.println("ccw");
}
else{
w.println("undefined");
}
}
else if(i>j){
int val=i-j;
int val2=4-val;
if((n-val+4)%4==0&&(n-val2+4)%4!=0){
w.println("ccw");
}
else if((n-val2+4)%4==0&&(n-val+4)%4!=0){
w.println("cw");
}
else{
w.println("undefined");
}
}
else{
w.println("undefined");
}
w.close();
}
static class pair{
int a,b,dis,time;
pair(int c,int d){
a=c;
b=d;
}
}
static long power(long x,long y){
if(y==0)return 1%mod;
if(y==1)return x%mod;
long res=1;
x=x%mod;
while(y>0){
if((y%2)!=0){
res=(res*x)%mod;
}
y=y/2;
x=(x*x)%mod;
}
return res;
}
static int gcd(int a,int b){
if(b==0)return a;
return gcd(b,a%b);
}
static void sev(int a[],int n){
for(int i=2;i<=n;i++)a[i]=i;
for(int i=2;i<=n;i++){
if(a[i]!=0){
for(int j=2*i;j<=n;){
a[j]=0;
j=j+i;
}
}
}
}
static class node{
int y;
int val;
node(int a,int b){
y=a;
val=b;
}
}
static class InputReader
{
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream)
{
this.stream = stream;
}
public int read()
{
if (numChars==-1)
throw new InputMismatchException();
if (curChar >= numChars)
{
curChar = 0;
try
{
numChars = stream.read(buf);
}
catch (IOException e)
{
throw new InputMismatchException();
}
if(numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine()
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
public int nextInt()
{
int c = read();
while(isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
int res = 0;
do
{
if(c<'0'||c>'9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
long res = 0;
do
{
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public double nextDouble()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.')
{
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.')
{
c = read();
double m = 1;
while (!isSpaceChar(c))
{
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public String readString()
{
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do
{
res.appendCodePoint(c);
c = read();
}
while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c)
{
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next()
{
return readString();
}
public interface SpaceCharFilter
{
public boolean isSpaceChar(int ch);
}
}
}
| JAVA |
834_A. The Useless Toy | <image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | 2 | 7 | s = input()
a, b = s.split()
d = "^>v<"
n = int(input()) % 4
if n == 2 or n == 0:
print("undefined")
elif n == 1:
if s in ["^ >", "> v", "v <", "< ^"]:
print("cw")
else:
print("ccw")
else:
if s in ["^ >", "> v", "v <", "< ^"]:
print("ccw")
else:
print("cw") | PYTHON3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.