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. PHP写一个 Api接口需要注意哪些?考虑哪些?

    随着互联网的飞速发展,前后端分离的开发模式越来越流行.编写一个稳定.可靠和易于使用的 API 接口是现代互联网应用程序的关键.本文将介绍在使用 thinkphp6 框架开发 API 接口时需要注意的要 ...

  2. 【项目源码】基于JSP动漫论坛的设计与实现

    动漫论坛项目主要用于实现动漫爱好者的互相交流,基本功能包括:注册用户.登录.浏览帖子.发布新帖.回复帖子.等.本系统结构如下: (1)普通用户: 注册用户:如果用户为非会员用户,通过注册,经审核通过之 ...

  3. 用OLED屏幕播放视频(3): 使用cuda编程加速视频处理

    下面的系列文章记录了如何使用一块linux开发扳和一块OLED屏幕实现视频的播放: 项目介绍 为OLED屏幕开发I2C驱动 使用cuda编程加速视频处理 这是此系列文章的第3篇, 主要总结和记录了如何 ...

  4. BZ全景可视化编辑器 (KRPano可视化编辑器, 无需编写任何代码制作全景漫游)

    软件简介 BZ全景编辑器是一款KRPano全景可视化编辑工具,下载安装即可使用,无需拥有任何KRPano代码基础,便可以制作生成精美的全景漫游作品. 官方网站: 点击进入官方网站 最新版软件下载地址: ...

  5. tree-test

    #include <iostream> #include <stack> using namespace std; typedef struct BiTNode{ char d ...

  6. 「codeforces - 1674F」Madoka and Laziness

    link. 如果做过 codeforces - 1144G 那这题最多 *2200. 序列中的最大值必然为其中一个拐点,不妨设 \(a_p = a_\max\),先讨论另一个拐点 \(i\) 在 \( ...

  7. 【Python爬虫】使用代理ip进行网站爬取

    使用代理IP进行网站爬取可以有效地隐藏你的真实IP地址,让网站难以追踪你的访问行为.本文将介绍Python如何使用代理IP进行网站爬取的实现,包括代理IP的获取.代理IP的验证.以及如何把代理IP应用 ...

  8. IO流知识汇总(不断更新)

    BIO.NIO.AIO有什么区别? BIO.NIO.AIO是Java中用于处理IO的三种不同的方式,它们之间的区别如下: BIO(Blocking IO):同步阻塞IO,传统的IO模型,也称为传统IO ...

  9. Vue框架快速上手

    Vue基础 vue指令 内容绑定 v-text 设置标签的内容一般通过双大括号的表达式{{ }}去替换内容 {{ hello }} v-html 与v-text类似区别在于html中的结构会被解析为标 ...

  10. ssr服务器极致渲染

    域名 RDS 云服务器 ECS 中国站   文档购物车ICP备案控制台   金秋上云季     首页 技术与产品   社区   直播   开发者学堂   开发者云   工具与资源中心   天池大赛 飞 ...