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的更多相关文章
随机推荐
- 异常处理,约束,MD5加密日志处理
程序运行过程中产生的错误, 不正常 def chufa(a, b): try: # 尝试执行xxx代码 ret = a/b # 如果这里出现了错误. 异常. 系统内部会产生一个异常对象. 系统会把这个 ...
- Shell - 简明Shell入门05 - 条件语句(Case)
示例脚本及注释 #!/bin/bash var=$1 # 将脚本的第一个参数赋值给变量var case $var in right) echo "Right!";; wrong) ...
- MVC3学习:利用jquery+ajax生成二维码(支持中文)
二维码越来越热火了,做电子商务网站,不做二维码,你就OUT了. 一.下载DLL文件(ThoughtWorks.QRCode.dll),并在项目中引用.点此下载 如果你还不知道什么是QRCode二维码, ...
- ES配置文件中文版
##################### Elasticsearch Configuration Example ##################### # This file contains ...
- 改善android性能工具篇【zipalign】
什么是Zipalign? Zipalign是一个android平台上整理APK文件的工具,它首次被引入是在Android 1.6版本的SDK软件开发工具包中.它能够对打包的Android应用 ...
- asp.net调用js方法
C#前台js调用后台代码 前台js <script type="text/javascript" language="javascript"> fu ...
- springboot @value和@configurationproperties注解的区别
@ConfigurationProperties @value 功能 批量注入配置文件中的属性 一个个指定 松散绑定(松散语法) 支持 不支持 SpEL 不支持 支持 JSR303数据校验 支持 ...
- Vue.js基础拾遗
本篇目录: 模版语法 插值 指令 v-bind指令 v-on指令 计算属性与侦听器 计算属性VS方法 计算属性VS侦听属性 Class与Style绑定 绑定HTML Class 绑定内联样式 条件渲染 ...
- 31-hadoop-hbase-mapreduce操作hbase
有一些大的文件,需要存入HBase中,其思想是先把文件传到HDFS上,利用map阶段读取<key,value>对,可在reduce把这些键值对上传到HBase中. HbaseMapper: ...
- springMVC上传文件简单案例
html <form name="Form2" action="/SpringMVC006/fileUpload2" method="post& ...