您的位置:首页 > 其它

#426 (Div. 2) A. The Useless Toy

2017-08-17 19:52 489 查看
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.

Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):

After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.

Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.

Input

There are two characters in the first string – the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.

In the second strings, a single number n is given (0 ≤ n ≤ 109) – the duration of the rotation.

It is guaranteed that the ending position of a s
4000
pinner is a result of a n second spin in any of the directions, assuming the given starting position.

Output

Output cw, if the direction is clockwise, ccw – if counter-clockwise, and undefined otherwise.

Examples

input

^ >

1

output

cw

input

< ^

3

output

ccw

input

^ v

6

output

undefined

题解:

给定初始位置和末尾置,判断其旋转顺序,如果逆时针和顺时针都可以,则输出undefined。逆时针输出ccw,顺时针输出cw。

模拟一下即可,水题。

代码:

#include <bits/stdc++.h>

using namespace std;
int c[4]={118,60,94,62};
map<int,int> m;
int solve(int s,int e,int n)
{
if(n%2==0) return 0;
int t=n%4;
if((s+t)%4==e) return 2;
if((s-t+4)%4==e) return 1;
return 0;
}

int main()
{
m[118]=0;
m[60]=1;
m[94]=2;
m[62]=3;
char s,e;
cin>>s>>e;
int scode=(int)s;
int ecode=(int)e;
int sindex=m[scode];
int eindex=m[ecode];

int num;
cin>>num;

int flag;
flag=solve(sindex,eindex,num);
if(flag==2) cout<<"cw"<<endl;
else if(flag==1) cout<<"ccw"<<endl;
else cout<<"undefined"<<endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: