zoukankan      html  css  js  c++  java
  • Codeforces 271 Div 2 A Keyboard

    题目链接:http://codeforces.com/contest/474/problem/A

    解题报告:一个矩形的键盘,上面只有规定的字符,现在按的时候总是会向某个方向按偏,也就是输入一串字符后,这串字符其实不是我要输入的字符,偏的方向只有左跟右,现在给你每次偏的方向跟输入的字符,让你求原来想要的字符串。注意不会出现按到键盘外的情况。

    直接键盘上所有的字符先存到一起,然后左偏取的时候+1,右偏取的时候-1就行了。

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<iostream>
     4 #include<algorithm>
     5 using namespace std;
     6 
     7 char str[105];
     8 int main()
     9 {
    10     char ch[20];
    11     char dir[200] = "qwertyuiopasdfghjkl;zxcvbnm,./";
    12     while(scanf("%s",ch)!=EOF)
    13     {
    14         scanf("%s",str);
    15         int flag = -1;
    16         if(ch[0] == 'L') flag = 1;
    17         int len = strlen(str),n = strlen(dir);
    18         for(int i = 0;i < len;++i)
    19         {
    20             for(int j = 0;j < n;++j)
    21             if(dir[j] == str[i])
    22             {
    23                 printf("%c",dir[j+flag]);
    24                 break;
    25             }
    26         }
    27         puts("");
    28     }
    29     return 0;
    30 }        
    View Code
  • 相关阅读:
    Oracle第五周测验
    软件测试第五周
    Oracle第四周作业
    c++第二章测试
    软件测试第四章
    软件测试 第三章
    Centos 安装.NET Core环境
    .net core 集成极光推送
    Swagger添加文件上传测试
    linux firewall
  • 原文地址:https://www.cnblogs.com/xiaxiaosheng/p/4009148.html
Copyright © 2011-2022 走看看