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的更多相关文章
随机推荐
- 14_python 匿名函数,递归函数
一.匿名函数 语法: 函数名 = lambda 参数: 返回值 # lambda x,y,z=1:x+y+z 注意: 1.函数的参数可以有多个. 多个参数之间⽤逗号隔开 2.匿名函数不管多复杂 ...
- redis 在 Linux下的安装
redis 和 nginx 一样,都是C语言编写的,所以我们的准备gcc 环境, 之前已经准备好了 没有准备的话(CentOs 有自带):yum install gcc-c++ 解压redis : ...
- jspm 简介
借鉴:http://www.jianshu.com/p/4aba847b3e8c 功能 1. 支持加载JavaScript各种模块化的写法:AMD.CommonJS.标准化的ES6模块... 2. 包 ...
- MySQL order by的实现
1.使用索引的已有顺序 2.filesort算法 filesort算法的执行流程 filesort相关的参数 sort_buffer_size 算法排序缓冲区的大小,线程级缓存 max_l ...
- odoo开发笔记 -- 官方模块一览表
模块名称 技术名称 作者 电子发票管理 account OpenERP SA 会计与财务 account_accountant OpenERP SA 合同管理 account_analytic_ana ...
- Linux发邮件
一.mail命令 1.配置 vim /etc/mail.rc 文件尾增加以下内容 set from=1968089885@qq.com smtp="smtp.qq.com"set ...
- C++学习知识点
所谓的学习,知识只是一部分,理解知识是如何被抽象和提炼的过程,才是更重要的 1.c++代码里面的\(反斜杠) C语言的宏要求只能在同一行,是不能跨行的.这里的反斜杠就是告诉编译器,我这里虽然换行了,但 ...
- 在vue中使用vuex 一个简单的实例
1.安装vuex:npm install vuex --save 2.在main.js文件中引入vuex (请忽略其它代码) 3.建一个vuex文件夹,然后在建一个store.js(这两个文件名字可以 ...
- logstash-1-安装配置
centos logstash logstash logstash是什么呢, 他是一个数据管道, JRuby编写的运行在java虚拟机的具有收集, 分析和转发数据流功能的工具 特性: 安装 1), w ...
- Percona XtraDB Cluster
简介 Percona XtraDB Cluster是MySQL高可用性和可扩展性的解决方案,Percona XtraDB Cluster提供的特性如下: 1.同步复制,事务要么在所有节点提交或不提交. ...