• Codeforces Round #271 (Div. 2)-A. Keyboard


    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[30] = {
     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 
    10 int main(){
    11     int i, j, len, pos;
    12     char to, str[110];
    13     while(scanf("%c", &to) != EOF){
    14         getchar();
    15         gets(str);
    16         len = strlen(str);
    17         if(to == 'R'){
    18             for(i = 0; i< len; i++){
    19                 for(j = 0; j < 30; j++){
    20                     if(str[i] == c[j]){
    21                         if(j <= 9){
    22                             printf("%c", c[(j + 9) % 10]);
    23                         }
    24                         else if(j <= 19){
    25                             printf("%c", c[(j + 19) % 20]);
    26                         }
    27                         else{
    28                             printf("%c", c[(j + 29) % 30]);
    29                         }
    30                     }
    31                 }
    32             }
    33         }
    34         else if(to == 'L'){
    35             for(i = 0; i< len; i++){
    36                 for(j = 0; j < 30; j++){
    37                     if(str[i] == c[j]){
    38                         if(j <= 9){
    39                             printf("%c", c[(j + 11) % 10]);
    40                         }
    41                         else if(j <= 19){
    42                             printf("%c", c[(j + 21) % 20]);
    43                         }
    44                         else{
    45                             printf("%c", c[(j + 31) % 30]);
    46                         }
    47                     }
    48                 }
    49             }
    50         }
    51         printf(" ");
    52     }
    53     return 0;

    54 } 

  • 相关阅读:
    2019中国爱分析数据智能高峰论坛(北京)
    GIEC2019第六届全球互联网经济大会北京站震撼来袭!
    iDigital2019数字营销广告主峰会
    DOIS 2019 DevOps国际峰会北京站来袭~
    QCon2019全球软件开发大会广州站即将来袭
    DTCC2019第十届中国数据库技术大会将于5月在北京召开
    2019第十四届中国竞争情报国际年会将于4月在上海召开
    第十二届GOPS全球运维大会2019深圳站即将开幕
    MTSC2019第五届中国移动互联网测试开发大会北京站震撼来袭!
    第八节:分支开发之合并到master
  • 原文地址:https://www.cnblogs.com/angle-qqs/p/4046894.html
Copyright © 2020-2023  润新知