A. Keyboard(思维水题) Codeforces Round #271 (Div. 2)

原题链接: http://codeforces.com/problemset/problem/474/A

在这里插入图片描述
测试样例

input
R
s;;upimrrfod;pbr
output
allyouneedislove

题意: 有一个初始键盘,现在一个盲人根据这个键盘按照左移或者右移的位置敲出一段字符串,现在你需要恢复这个字符串。

解题思路: 我们不要被这道题给误解了,当左移的时候左边界的字符是不会被敲到的,当右移的时候右边界的字符是不会被敲到的,所以我们可以将这个键盘连着一个序列,简单遍历查找字符所在的键盘位置,之后根据左移右移来选定其旁边的字符即可。

AC代码

/*
*blog:https://blog.csdn.net/hzf0701
*邮箱:unique_powerhouse@qq.com
*注:文章若有任何问题请私信我或评论区留言,谢谢支持。
*/
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)

using namespace std;

typedef long long ll;
const int maxn=1e5;//数组所开最大值
const int mod=1e9+7;//模
const int inf=0x3f3f3f3f;//无穷大

string s="qwertyuiopasdfghjkl;zxcvbnm,./";
string str;
char op;
int len2=s.size();
void solve(){
    int len1=str.size();
    rep(i,0,len1-1){
        rep(j,0,len2-1){
            if(s[j]==str[i]){
                if(op=='R'){
                    cout<<s[j-1];
                }
                else{
                    cout<<s[j+1];
                }
                break;
            }
        }
    }
    cout<<endl;
}
int main(){
    while(cin>>op>>str){
        solve();
    }
    return 0;
}

posted @ 2022-03-26 16:49  unique_pursuit  阅读(9)  评论(0)    收藏  举报