http://codeforces.com/problemset/problem/474/A

A. Keyboard
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

Print a line that contains the original message.

Sample test(s)
input
R
s;;upimrrfod;pbr
output
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的更多相关文章

  1. Codeforces Round #271 (Div. 2)题解【ABCDEF】

    Codeforces Round #271 (Div. 2) A - Keyboard 题意 给你一个字符串,问你这个字符串在键盘的位置往左边挪一位,或者往右边挪一位字符,这个字符串是什么样子 题解 ...

  2. Codeforces Round #271 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/474 A题:Keyboard 模拟水题. 代码例如以下: #include <iostream> #include ...

  3. Codeforces Round #271 (Div. 2)

    A. Keyboard 题意:一个人打字,可能会左偏一位,可能会右偏一位,给出一串字符,求它本来的串 和紫书的破损的键盘一样 #include<iostream> #include< ...

  4. Codeforces Round #271 (Div. 2) F. Ant colony (RMQ or 线段树)

    题目链接:http://codeforces.com/contest/474/problem/F 题意简而言之就是问你区间l到r之间有多少个数能整除区间内除了这个数的其他的数,然后区间长度减去数的个数 ...

  5. Codeforces Round #271 (Div. 2) D. Flowers (递推)

    题目链接:http://codeforces.com/problemset/problem/474/D 用RW组成字符串,要求w的个数要k个连续出现,R任意,问字符串长度为[a, b]时,字符串的种类 ...

  6. Codeforces Round #271 (Div. 2) E题 Pillars(线段树维护DP)

    题目地址:http://codeforces.com/contest/474/problem/E 第一次遇到这样的用线段树来维护DP的题目.ASC中也遇到过,当时也非常自然的想到了线段树维护DP,可是 ...

  7. Codeforces Round #271 (Div. 2) F题 Ant colony(线段树)

    题目地址:http://codeforces.com/contest/474/problem/F 由题意可知,最后能够留下来的一定是区间最小gcd. 那就转化成了该区间内与区间最小gcd数相等的个数. ...

  8. 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 ...

  9. Codeforces Round #271 (Div. 2) F ,E, D, C, B, A

    前言:最近被线段树+简单递推DP虐的体无完肤!真是弱! A:简单题,照着模拟就可以,题目还特意说不用处理边界 B:二分查找即可,用lower_lound()函数很好用 #include<stri ...

随机推荐

  1. swift4.0 方法监听Selector写法总结

    import UIKit class MainViewController: UITabBarController { //MARK:属性 懒加载 lazy var composeBtn = UIBu ...

  2. Event事件的三个阶段

    转自www.w3school.com.cn/htmldom/event_bubbles.asp 在 2 级 DOM标准中,事件传播分为三个阶段: 第一,捕获阶段.事件从 Document 对象沿着文档 ...

  3. 【Luogu P1502】 窗口的星星

    →传送窗口 (复制一下题面好了~) 题目背景 小卡买到了一套新房子,他十分的高兴,在房间里转来转去. 题目描述 晚上,小卡从阳台望出去,“哇~~~~好多星星啊”,但他还没给其他房间设一个窗户,天真的小 ...

  4. sequence(2018.10.23)

    建出差分序列,可以发现最早出现的回文串就是答案,自己想想就懂了. \(O(N)\)找出回文串就好了,字符串\(hash\)或者\(manacher\)都能在合法时间内得到答案. #include< ...

  5. foreach循环报NPE空指针异常

    前言 最近debug时忽然发现,如果一个集合赋值为null,那么对该集合进行foreach循环(也叫增强for循环)时,会报NPE(即空指针异常NullPointerException). 代码如下: ...

  6. Hexo搭建博客教程(1) - 安装环境与本地搭建

    前言 搭建个人博客一般有两种选择,一个是使用WordPress,但是需要将博客搭建在服务器上,不过搭建好后写文章方便,适合没有程序基础的人使用.另一个是使用Hexo,相对简洁高效,不需要服务器,既可以 ...

  7. VLAN-1-VLAN配置

    f0/12和f0/24不在列表中,因为它们动态地成为trunk,支持多个vlan       “unsup”意为这个2950交换机不支持FDDI和TR       首先 switchport mode ...

  8. Tinghua Data Mining 2

    数据预处理 https://www.bilibili.com/video/av23933161/?p=11 http://www.xuetangx.com/courses/course-v1:Tsin ...

  9. Mass Change Queries Codeforces - 911G

    https://codeforces.com/contest/911/problem/G 没想到线段树合并还能这么搞.. 对每个权值建一个线段树(动态开点),如果权值为k的线段树上第i位为1,那么表示 ...

  10. python学习day13

    目录 JavaScript Dom jQuery JavaScript JavaScript 是世界上最流行的编程语言. 这门语言可用于 HTML 和 web,更可广泛用于服务器.PC.笔记本电脑.平 ...