A. The Useless Toy
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard 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

题目大意:判断第二个字符是不是第一个字符通过n步逆时针或顺时针得到,如果得不到准确的答案,输出undefined。

思路:模拟。取n%4的值,如果为0或2输出undefined,因为这个时候如果答案对,那么我们分不出顺逆。答案不对更是undefined。

这样只要处理余数为1,3 的情况了。

AC代码如下:

 1 #include<iostream>
2 #include<stdio.h>
3 using namespace std;
4 char x[]={'v','<','^','>'};
5 char x2[]={'v','>','^','<'};
6 int main()
7 {
8 char a,c;
9 int n;
10 cin>>a>>c;
11 scanf("%d",&n);
12 if(n%4==2||n%4==0){
13 printf("undefined\n");
14 }else{
15 int now,nxt=n;
16 bool flag=false;
17 for(int i=0;i<4;i++){
18 if(x[i]==a){
19 now=i;
20 break;
21 }
22 }
23 for(int i=now;;i++){
24 i=i%4;
25 if(i==(nxt+now)%4){
26 if(x[i]==c)
27 flag=true;
28 break;
29 }
30 }
31 if(flag){
32 cout<<"cw"<<endl;
33 return 0;
34 }else{
35 for(int i=0;i<4;i++){
36 if(x2[i]==a){
37 now=i;
38 break;
39 }
40 }
41 for(int i=now;;i++){
42 i=i%4;
43 if(i==(nxt+now)%4){
44 if(x2[i]==c)
45 flag=true;
46 break;
47 }
48 }
49 }
50 if(flag){
51 cout<<"ccw"<<endl;
52 return 0;
53 }else{
54 cout<<"undefined"<<endl;
55 return 0;
56 }
57 }
58 return 0;
59 }

Codeforces Round #426 (Div. 2) A. The Useless Toy的更多相关文章

  1. CodeForces 834C - The Meaningless Game | Codeforces Round #426 (Div. 2)

    /* CodeForces 834C - The Meaningless Game [ 分析,数学 ] | Codeforces Round #426 (Div. 2) 题意: 一对数字 a,b 能不 ...

  2. Codeforces Round #426 (Div. 2)【A.枚举,B.思维,C,二分+数学】

    A. The Useless Toy time limit per test:1 second memory limit per test:256 megabytes input:standard i ...

  3. Codeforces Round #426 (Div. 2)

    http://codeforces.com/contest/834 A. The Useless Toy 题意: <,>,^,v这4个箭头符号,每一个都可以通过其他及其本身逆时针或者顺时针 ...

  4. Codeforces Round #426 (Div. 2)A B C题+赛后小结

    最近比赛有点多,可是好像每场比赛都是被虐,单纯磨砺心态的作用.最近讲的内容也有点多,即便是点到为止很浅显的版块,刷了专题之后的状态还是~"咦,能做,可是并没有把握能A啊".每场网络 ...

  5. Codeforces Round #426 (Div. 2) A,B,C

    A. The Useless Toy 题目链接:http://codeforces.com/contest/834/problem/A 思路: 水题 实现代码: #include<bits/st ...

  6. Codeforces Round #426 (Div. 2)A题&&B题&&C题

    A. The Useless Toy:http://codeforces.com/contest/834/problem/A 题目意思:给你两个字符,还有一个n,问你旋转n次以后从字符a变成b,是顺时 ...

  7. 【Codeforces Round #426 (Div. 2) A】The Useless Toy

    [Link]:http://codeforces.com/contest/834/problem/A [Description] [Solution] 开个大小为4的常量字符数组; +n然后余4,-n ...

  8. Codeforces Round #426 (Div. 2) C. The Meaningless Game

    C. The Meaningless Game 题意: 两个人刚刚开始游戏的时候的分数, 都是一分, 然后随机一个人的分数扩大k倍,另一个扩大k的平方倍, 问给你一组最后得分,问能不能通过游戏得到这样 ...

  9. 【Codeforces Round #426 (Div. 2) B】The Festive Evening

    [Link]:http://codeforces.com/contest/834/problem/B [Description] [Solution] 模拟水题; 注意一个字母单个出现的时候,结束和开 ...

  10. 【Codeforces Round #426 (Div. 2) C】The Meaningless Game

    [Link]:http://codeforces.com/contest/834/problem/C [Description] 有一个两人游戏游戏; 游戏包括多轮,每一轮都有一个数字k,赢的人把自己 ...

随机推荐

  1. 高德Android高性能高稳定性代码覆盖率技术实践

    ​前言 代码覆盖率(Code coverage)是软件测试中的一种度量方式,用于反映代码被测试的比例和程度. 在软件迭代过程中,除了应该关注测试过程中的代码覆盖率,用户使用过程中的代码覆盖率也是一个非 ...

  2. linux tcpdump 使用小结(二)

    转载请注明出处: TCPDump是一个功能强大的网络抓包工具,它能够在命令行界面捕获.分析和解析网络数据包.下面是TCPDump命令的使用总结,包括使用语法.常用参数说明等: 使用语法:tcpdump ...

  3. Matplotlib(一)

    Matplotlib(一) Matplotlib库的介绍 Matplotlib库的使用 Matplotlib库由各种可视化类构成,内部结构复杂,受Matlab启发matplotlib.pyplot是绘 ...

  4. P251——用RadialGradientBrush填充椭圆,并进行RotateTransform变换

    一.认识RadialGradientBrush(径向渐变) 1.坐标 RadialGradientBrush可以用来填充矩形(正方形)和椭圆(正圆), 填充区域使用比例坐标, 椭圆的坐标(0,0)和( ...

  5. Solution -「BalticOI 2004」Sequence

    Description Link. Given is a sequencen \(A\) of \(n\) intergers. Construct a stricly increasing sequ ...

  6. mount时候遇到写保护,将以只读方式挂载

    mount时候遇到写保护,将以只读方式挂载 遇到 mount: 未知的文件系统类型"(null)" [root@localhost ~]# mount /dev/sdb /mnt/ ...

  7. Harry Potter RPG_1

    RPG--Harry Potter 博主最近迷上了<Harry Potter> So 我制作了一款RPG对话模拟游戏, 目前主线以进行到了分院以后: 有兴趣的小伙伴可以看看,能点个关注就更 ...

  8. 深入解析枚举(Enum):在程序设计中的应用与优势

    深入解析枚举(Enum):在程序设计中的应用与优势 引言 在程序设计中,我们经常需要用到一组具名的常量,这些常量表示一些有限的离散状态或取值范围.例如,表示方向(上.下.左.右).星期几.性别等.为了 ...

  9. 教育法学第九章单元测试MOOC

    第九章单元测试 返回 本次得分为:100.00/100.00, 本次测试的提交时间为:2020-09-06, 如果你认为本次测试成绩不理想,你可以选择 再做一次 . 1 单选(5分) 作为教师最基本的 ...

  10. 手写商用Java虚拟机HotSpot,疯狂磨砺技术中

    在当前Java行业激烈竞争的形式下,唯有掌握技术,心中才不能慌.在多年前,我就开始苦练底层技术,但是眼看百遍也不如手过一遍,所以我打算把虚拟机的精华实现部分用手敲出来,这个过程注定不会轻松,但是心态不 ...