Codeforces Round #426 (Div. 2) A. The Useless Toy
来源:互联网 发布:ubuntu ssh 安装 编辑:程序博客网 时间:2024/06/08 05:17
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.
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 cw, if the direction is clockwise,ccw – if counter-clockwise, and undefined otherwise.
^ >1
cw
< ^3
ccw
^ v6
undefined
坑点是如果顺时针和逆时针都可以变成需要的字符时算是undefined的
代码又臭又长,凑合一下吧.......
#include<iostream>using namespace std;char ch1,ch2;int n,flag=0,fflag=0;void clockwise(char ch,int a){if(ch=='^'){if(a%4==1) ch1='>';else if(a%4==2) ch1='v';else if(a%4==3) ch1='<';else ch1='^';}if(ch=='<'){if(a%4==1) ch1='^';else if(a%4==2) ch1='>';else if(a%4==3) ch1='v';else ch1='<';}if(ch=='v'){if(a%4==1) ch1='<';else if(a%4==2) ch1='^';else if(a%4==3) ch1='>';else ch1='v';}if(ch=='>'){if(a%4==1) ch1='v';else if(a%4==2) ch1='<';else if(a%4==3) ch1='^';else ch1='>';}}void counterclockwise(char ch,int a){if(ch=='^'){if(a%4==1) ch1='<';else if(a%4==2) ch1='v';else if(a%4==3) ch1='>';else ch1='^';}if(ch=='<'){if(a%4==1) ch1='v';else if(a%4==2) ch1='>';else if(a%4==3) ch1='^';else ch1='<';}if(ch=='v'){if(a%4==1) ch1='>';else if(a%4==2) ch1='^';else if(a%4==3) ch1='<';else ch1='v';}if(ch=='>'){if(a%4==1) ch1='^';else if(a%4==2) ch1='<';else if(a%4==3) ch1='v';else ch1='>';}}int main(){char chh;scanf("%c %c",&ch1,&ch2);chh=ch1;getchar();cin>>n;clockwise(ch1,n);if(ch1==ch2){flag=1;//cout<<"cw"<<endl;//return 0;}ch1=chh;counterclockwise(ch1,n);if(ch1==ch2){fflag=1;//cout<<"ccw"<<endl;//return 0;}if(flag==1&&!fflag) cout<<"cw"<<endl;if(!flag&&fflag==1) cout<<"ccw"<<endl;if((!flag&&!fflag)||(flag==1&&fflag==1)) cout<<"undefined"<<endl;}
- Codeforces Round #426 (Div. 2) A. The Useless Toy
- Codeforces Round #426 (Div. 2)-A. The Useless Toy
- Codeforces Round #426 (Div. 2) A The Useless Toy
- Codeforces Round #426 (Div. 2) A. The Useless Toy
- Codeforces Round #426 (Div. 2) A The Useless Toy
- Codeforces Round #426 (Div. 2) A. The Useless Toy
- Codeforces Round #426 (Div. 2) The Useless Toy
- Codeforces Round #426 (Div. 2) The Useless Toy 数组环
- #426 (Div. 2) A. The Useless Toy
- (模拟)Codeforces Round #426 A. The Useless Toy
- 【CodeForces】426Div2 A The Useless Toy
- Codeforces 834A-The Useless Toy
- Codeforces 834 A The Useless Toy
- CodeForces 834A The Useless Toy
- codeforces 834-A. The Useless Toy
- codeforces 834A The Useless Toy
- 【CodeForces】834A The Useless Toy 水
- Codeforces 843A:The Useless Toy
- 【Java并发编程】线程池
- WM基本功能
- NYOJ 236 心急的C小加
- 图结构练习——BFSDFS——判断可达性
- list.remove报错解决方案
- Codeforces Round #426 (Div. 2) A. The Useless Toy
- InfluxDB入门教程
- Android项目中main方法运行报错
- Java实现-单词切分
- lua 报错 (a nil value) 是说对一个nil进行了操作
- 四色问题 zoj1084
- 水题:51Nod1432-独木舟
- linux中淘宝tengine安装配置
- 【思维】833A