您的位置:首页 > 其它

Codeforces 843A:The Useless Toy

2017-11-13 16:36 399 查看
题目:

Codeforces 843A:The Useless Toy

Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.

Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner 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 spinner is a result of a n second spin in any of the directions, assuming the given starting position.

Output

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

Example

Input

^ >

1

Output

cw

Input

< ^

3

Output

ccw

Input

^ v

6

Output

undefined

题意:

大体上一看停吓唬人的,读完之后会发现其实不难;就是四个符号表示4个方向,给出初始和结束的方向以及旋转的次数,需要我们判断旋转的方向。

分析:

这四个符号分别有4个ASCII码值,我的方法是0123为下标存在长度为4的数组中,根据给出的符号判断是哪两个数;根据题意知道不定义的方向一是只要两个方向相反或者相同,二是两个方向和给出的旋转次数不符合。因此我们只要找出符合要求的,即两个方向相邻时旋转次数n与一个方向的值(0123)中一个相加再模4,看是否等于另一个方向的值(记得两个方向不相同也不相反)即可判断旋转方向;其余情况均为未定义。

代码如下:

#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
char a, b;
long long n;
while(cin >> a >> b)
{
cin
4000
>> n;
int ar[4] = {94, 62, 118, 60};
long long p1, p2;
for(int i = 0; i < 4; i++)
{
if((int)a == ar[i])
p1 = i;
if((int)b == ar[i])
p2 = i;
}
if(abs(p1 - p2) == 2 || p1 == p2)
cout << "undefined" << endl;
else
{
if((p2 + n) % 4 == p1)
cout << "ccw" << endl;
else if((p1 + n) % 4 == p2)
cout << "cw" << endl;
else
cout << "undefined" << endl;
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: