Codeforces834A
A. The Useless Toy

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
//2017-08-18
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const char cw[] = {'^', '>', 'v', '<'};
const char ccw[] = {'^', '<', 'v', '>'}; int main()
{
int n;
char ch1, ch2;
while(cin>>ch1>>ch2){
cin>>n;
n = n%;
bool fg1 = false, fg2 = false;
for(int i = ; i < ; i++){
if(cw[i] == ch1 && cw[(i+n)%] == ch2){
fg1 = true;
}
}
for(int i = ; i < ; i++){
if(ccw[i] == ch1 && ccw[(i+n)%] == ch2){
fg2 = true;
}
}
if(fg1 && !fg2)
cout<<"cw"<<endl;
else if(!fg1 && fg2)
cout<<"ccw"<<endl;
else
cout<<"undefined"<<endl;
} return ;
}
Codeforces834A的更多相关文章
随机推荐
- OC中双向链表的实现
双向链表的概念 双向链表也叫双链表,是链表的一种,它的每个数据结点中都有两个指针,分别指向直接后继和直接前驱.所以,从双向链表中的任意一个结点开始,都可以很方便地访问它的前驱结点和后继结点.一般我们都 ...
- git fetch 、git pull 与 git pull --rebase
1. git fetch 与 git pull 都是从远程拉取代码到本地,git fetch只是拉取到本地,git pull不仅拉取到本地还merge到本地分支中.所以git pull是git fet ...
- Smart/400开发上手3: 练习实践
练习题 在2006年1月1日之前入职且在职的营销员,给予年资补贴2000元: 符合以上条件的,再按以下标准一次性发放职级补贴: 职级代码 简称 补偿金额 A1 AD 6000 B1 SBM 5000 ...
- 利用净现值(NPV)分析对比方案的可行性
最近在学经济管理方面课程,发现一个挺有意思的例题,mark一下. 题目描述 某投资项目有A.B两个方案,有关数据如下表,基准折现率为10%,请问那个方案较优? 项目 A方案 B方案 投资 15 3 年 ...
- awk将某个字段按照分隔符分割之后统计次数
cat label_movie2|grep BBD252CC0A4FE7D10C990261D5CEACB5|awk -F "," '{for(i=2;i<NF;i++) p ...
- shell信号捕捉命令 trap
trap 命令 tarp命令用于在接收到指定信号后要执行的动作,通常用途是在shell脚本被中断时完成清理工作.例如: 脚本在执行时按下CTRL+c时,将显示"program exit... ...
- crontab命令使用文档.txt
基本格式 : * * * * * command 分 时 日 月 周 命令 第1列表示分钟1-59 每分钟用*或者 */1表示 第2列表示小时1-23(0表示0点) 第3列表示日期1-31 第4列表示 ...
- (转)30 个实例详解 TOP 命令
原文:http://blog.jobbole.com/112873/?utm_source=blog Linux中的top命令显示系统上正在运行的进程.它是系统管理员最重要的工具之一.被广泛用于监视服 ...
- ecshop 安装出错gd_version
678: static function gd_version()
- 【转】多线程:C#线程同步lock,Monitor,Mutex,同步事件和等待句柄(上)
本篇从Monitor,Mutex,ManualResetEvent,AutoResetEvent,WaitHandler的类关系图开始,希望通过 本篇的介绍能对常见的线程同步方法有一个整体的认识,而对 ...