Codeforces Round #271 (Div. 2)-A. Keyboard
http://codeforces.com/problemset/problem/474/A
2 seconds
256 megabytes
standard input
standard output
Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way:
qwertyuiop
asdfghjkl;
zxcvbnm,./
Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That means that now he presses not a button he wants, but one neighboring button (left or right, as specified in input).
We have a sequence of characters he has typed and we want to find the original message.
First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right).
Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain spaces as there is no space on Mole's keyboard.
It is guaranteed that even though Mole hands are moved, he is still pressing buttons on keyboard and not hitting outside it.
Print a line that contains the original message.
R
s;;upimrrfod;pbr
allyouneedislove
解题思路:模拟手在标准键盘上面输入字符,L左移一格,R右移一格
1 #include <stdio.h>
2 #include <string.h>
3
4 char c[] = {
5 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p',
6 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';',
7 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/'
8 };
9
int main(){
int i, j, len, pos;
char to, str[];
while(scanf("%c", &to) != EOF){
getchar();
gets(str);
len = strlen(str);
if(to == 'R'){
for(i = ; i< len; i++){
for(j = ; j < ; j++){
if(str[i] == c[j]){
if(j <= ){
printf("%c", c[(j + ) % ]);
}
else if(j <= ){
printf("%c", c[(j + ) % ]);
}
else{
printf("%c", c[(j + ) % ]);
}
}
}
}
}
else if(to == 'L'){
for(i = ; i< len; i++){
for(j = ; j < ; j++){
if(str[i] == c[j]){
if(j <= ){
printf("%c", c[(j + ) % ]);
}
else if(j <= ){
printf("%c", c[(j + ) % ]);
}
else{
printf("%c", c[(j + ) % ]);
}
}
}
}
}
printf("\n");
}
return ;
54 }
Codeforces Round #271 (Div. 2)-A. Keyboard的更多相关文章
- Codeforces Round #271 (Div. 2)题解【ABCDEF】
Codeforces Round #271 (Div. 2) A - Keyboard 题意 给你一个字符串,问你这个字符串在键盘的位置往左边挪一位,或者往右边挪一位字符,这个字符串是什么样子 题解 ...
- Codeforces Round #271 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/474 A题:Keyboard 模拟水题. 代码例如以下: #include <iostream> #include ...
- Codeforces Round #271 (Div. 2)
A. Keyboard 题意:一个人打字,可能会左偏一位,可能会右偏一位,给出一串字符,求它本来的串 和紫书的破损的键盘一样 #include<iostream> #include< ...
- Codeforces Round #271 (Div. 2) F. Ant colony (RMQ or 线段树)
题目链接:http://codeforces.com/contest/474/problem/F 题意简而言之就是问你区间l到r之间有多少个数能整除区间内除了这个数的其他的数,然后区间长度减去数的个数 ...
- Codeforces Round #271 (Div. 2) D. Flowers (递推)
题目链接:http://codeforces.com/problemset/problem/474/D 用RW组成字符串,要求w的个数要k个连续出现,R任意,问字符串长度为[a, b]时,字符串的种类 ...
- Codeforces Round #271 (Div. 2) E题 Pillars(线段树维护DP)
题目地址:http://codeforces.com/contest/474/problem/E 第一次遇到这样的用线段树来维护DP的题目.ASC中也遇到过,当时也非常自然的想到了线段树维护DP,可是 ...
- Codeforces Round #271 (Div. 2) F题 Ant colony(线段树)
题目地址:http://codeforces.com/contest/474/problem/F 由题意可知,最后能够留下来的一定是区间最小gcd. 那就转化成了该区间内与区间最小gcd数相等的个数. ...
- Codeforces Round #271 (Div. 2)-B. Worms
http://codeforces.com/problemset/problem/474/B B. Worms time limit per test 1 second memory limit pe ...
- Codeforces Round #271 (Div. 2) F ,E, D, C, B, A
前言:最近被线段树+简单递推DP虐的体无完肤!真是弱! A:简单题,照着模拟就可以,题目还特意说不用处理边界 B:二分查找即可,用lower_lound()函数很好用 #include<stri ...
随机推荐
- 洛谷 - P1414 - 又是毕业季II - 因数
https://www.luogu.org/problemnew/show/P1414 以后这种gcd的还是尽可能往分解那里想一下. 先把每个数分解,他的所有因子都会cnt+1. 然后从最大的可能因子 ...
- WPF 中如何使得DataGrid的Column有鼠标点击相应
http://stackoverflow.com/questions/5895803/how-do-i-capture-click-events-on-a-datagrid-column-header ...
- [HNOI2010] 矩阵 matrix
标签:dfs+剪枝. 题解: 这道题看着就像一道dfs题目,没有什么算法可以用来算这个东西,于是想想暴搜. 如果我们确定因为是2*2的子矩阵的和,如果确定了其中三个,那么就可以确定第四个,发现如果确定 ...
- ZOJ 4019 Schrödinger's Knapsack (from The 18th Zhejiang University Programming Contest Sponsored by TuSimple)
题意: 第一类物品的价值为k1,第二类物品价值为k2,背包的体积是 c ,第一类物品有n 个,每个体积为S11,S12,S13,S14.....S1n ; 第二类物品有 m 个,每个体积为 S21,S ...
- VLAN-1-VLAN配置
f0/12和f0/24不在列表中,因为它们动态地成为trunk,支持多个vlan “unsup”意为这个2950交换机不支持FDDI和TR 首先 switchport mode ...
- 基于PHP的正则表达式
用法 从某个字符抽取信息 用新文本替换匹配的文本 把字符串拆分成小块字符串组成的数组 基础 preg_match('/需要匹配的正则表达式/', '字符串'); 正则匹配模式 集合: [xxxx]-- ...
- AKOJ-1265-输出二叉树
链接:https://oj.ahstu.cc/JudgeOnline/problem.php?id=1265 题意: 我们知道二叉树的先序序列和中序序列或者是中序和后序能够唯一确定一颗二叉树.现在给一 ...
- 如何在spring环境中做单元测试
在测试类的上方加入以下注解 @RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration("classpath:spring.xm ...
- spring security 5 There is no PasswordEncoder mapped for the id "null" 错误
转载请注明出处 http://www.cnblogs.com/majianming/p/7923604.html 最近在学习spring security,但是在设置客户端密码时,一直出现了一下错误提 ...
- MySQL数据库报错:Too many connection
每次搭建环境运行一段时间,后台就会报错:com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data sourc ...