zoukankan      html  css  js  c++  java
  • 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 } 

  • 相关阅读:
    linux date使用
    SHELL输出带颜色字体
    vimrc配置
    你所不知道的C++
    temp
    说什么好呢3
    Extjs3 Combo实现百度搜索查询
    Extjs3笔记 fbar
    Extjs combo赋值与刷新的先后顺序
    sql中nvarchar(max)长度测试
  • 原文地址:https://www.cnblogs.com/angle-qqs/p/4046894.html
Copyright © 2011-2022 走看看