CF834A-The Useless Toy

来源:互联网 发布:microsoft c 软件下载 编辑:程序博客网 时间:2024/05/21 17:14

A. The Useless Toy

time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
这里写图片描述
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.

Examples
input
^ >
1
output
cw
input
< ^
3
output
ccw
input
^ v
6
output
undefined

题目大意:给出旋转次数,开始方向和最终方向,问是顺时针还是逆时针还是不确定。
解题思路:模运算

#include<iostream>#include<cstdio>#include<vector>#include<map>#include<set>#include<queue>#include<cmath>#include<string>#include<cstring>#include<algorithm>using namespace std;typedef long long LL;const LL INF=1e18;const int MAXN=60;const double eps=1e-10;int a[MAXN],n;int main(){    //cout<<-1%4<<endl;    char a,b;    int x,y;    while(scanf("%c %c",&a,&b)!=EOF)    {        getchar();        if(a==94) x=0;        else if(a==62) x=1;        else if(a==118) x=2;        else x=3;        if(b==94) y=0;        else if(b==62) y=1;        else if(b==118) y=2;        else y=3;        int n;scanf("%d",&n);        getchar();        //cout<<x<<" "<<y<<endl;        bool f1=false,f2=false;        //cout<<(x+n)%4<<" "<<(x-n+4)%4<<endl;        if((x+n)%4==y) f1=true;        //((x-n)%4<0?-(x-n)%4:(x-n)%4)==y        if(((x-n)%4<0?(x-n)%4+4:(x-n)%4)==y) f2=true;        if(f1&&f2) printf("undefined\n");        else if(f1) printf("cw\n");        else printf("ccw\n");    }    return 0;}
原创粉丝点击