16CF1-A

来源:互联网 发布:淘宝美工如何上新 编辑:程序博客网 时间:2024/06/04 08:12

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

Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner 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 undefinedotherwise.

Example
Input
^ >1
Output
cw
Input
< ^3
Output
ccw
Input
^ v6
Output
undefined

1、题意:就是符号V旋转,然后有四种形态分别是V,<,^,>,然后第一行给你四种形态中的两种,求第一种形态是怎么变成第二种形态的,然后第二行给你旋转的次数(每次旋转90°),如果顺时针旋转就输出cw,逆时针旋转就输出ccw,如果是其他情况(顺时针和逆时针都能让第一种形态变成第二种形态也算,我就在这儿错了一次),就输出undefined。
2、思路:一共就十二种情况,直接存数组然后判断了,不过忘记了旋转次数可以是0,在这儿又错了一次。
3、代码:

#include<iostream>using namespace std;struct f{char x;char y;}sp[12];int main(){int n,N,i;char a,b;sp[0].x='v';sp[1].x='v';sp[2].x='v';sp[0].y='<';sp[1].y='^';sp[2].y='>';sp[3].x='<';sp[4].x='<';sp[5].x='<';sp[3].y='^';sp[4].y='>';sp[5].y='v';sp[6].x='^';sp[7].x='^';sp[8].x='^';sp[6].y='>';sp[7].y='v';sp[8].y='<';sp[9].x='>';sp[10].x='>';sp[11].x='>';sp[9].y='v';sp[10].y='<';sp[11].y='^';int cw[12]={1,2,3,1,2,3,1,2,3,1,2,3};int ccw[12]={3,2,1,3,2,1,3,2,1,3,2,1};while(cin>>a>>b){cin>>n;for(i=0;i<12;i++){if(a==sp[i].x&&b==sp[i].y){N=i;break;}}if(n==0){cout<<"undefined"<<endl;continue;}if(n%4==0){cout<<"undefined"<<endl;continue;}if(n%4==cw[N]&&n%4==ccw[N]){cout<<"undefined"<<endl;continue;}if(n%4==cw[N]&&n%4!=ccw[N]){cout<<"cw"<<endl;continue;}if(n%4!=cw[N]&&n%4==ccw[N]){cout<<"ccw"<<endl;continue;}}return 0;}


4、总结:其实我这种方法算是偷懒了吧...

原创粉丝点击