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. XV6中的锁:MIT6.s081/6.828 lectrue10:Locking 以及 Lab8 locks Part1 心得

    这节课程的内容是锁(本节只讨论最基础的锁).其实锁本身就是一个很简单的概念,这里的简单包括 3 点: 概念简单,和实际生活中的锁可以类比,不像学习虚拟内存时,现实世界中几乎没有可以类比的对象,所以即使 ...

  2. 以程序员的视角,介绍如何通过API接口获取淘宝商品数据的方法和步骤,并提供实际代码示例

    ​ 当我们想要获取淘宝商品数据时,可以通过调用淘宝开放平台的API接口来实现.下面是一些步骤和示例代码来帮助你开始. 步骤1:申请开发者账号和应用 在开始之前,你需要在淘宝开放平台上注册一个开发者账号 ...

  3. 用OLED屏幕播放视频(2): 为OLED屏幕开发I2C驱动

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

  4. Docker 镜像库国内加速的几种方法

    概述 在国内,拉取 Docker 镜像速度慢/时不时断线/无账号导致限流等,比较痛苦. 这里提供加速/优化的几种方法. 梳理一下,会碰到以下情况: 国内下载速度慢/时不时断线:是因为网络被限制了. 没 ...

  5. 【目标检测】RCNN算法实现

    一.前言 RCNN(Regions with CNN features)算法由Ross Girshick在2014年的论文"Rich feature hierarchies for accu ...

  6. SQL Server查询数据库中的表

    SQL Server查询数据库中的表 SSMS中用不了MySQL中的show 查询当前数据库中所有表名: SELECT name FROM sysobjects WHERE (xtype = 'U') ...

  7. 5.0 CRC32校验技术概述

    CRC校验技术是用于检测数据传输或存储过程中是否出现了错误的一种方法,校验算法可以通过计算应用与数据的循环冗余校验(CRC)检验值来检测任何数据损坏.通过运用本校验技术我们可以实现对特定内存区域以及磁 ...

  8. 基于 Wiki.js 搭建知识库系统

    前言 本文介绍如何使用 Wiki.js 搭建知识库系统. Wiki.js 官网 安装 前提准备 Wiki.js 几乎可以在任何支持 Node.js 的系统上运行.它可以运行在 Linux .Windo ...

  9. PLC通过Modbus转Profinet网关与合康变频器Modbus通讯案例

    PLC通过Modbus转Profinet网关(XD-MDPN100)与合康变频器Modbus通讯,实现了两个设备之间的数据交互.Profinet是一种基于以太网的实时工控网络协议,而Modbus是一种 ...

  10. 云图说|初识API中心APIHub

    阅识风云是华为云信息大咖,擅长将复杂信息多元化呈现,其出品的一张图(云图说).深入浅出的博文(云小课)或短视频(云视厅)总有一款能让您快速上手华为云.更多精彩内容请单击此处. 摘要:API中心是为AP ...