码迷,mamicode.com
首页 > 其他好文 > 详细

CodeForces 474A Keyboard (水题)

时间:2016-07-12 22:58:48      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:

题意:给定一个键盘,然后一行字母,和一个字符,代表把那一行字母在键盘上左移还是右移一位。

析:没什么好说的,直接暴力就好。

代码如下:

#include<bits/stdc++.h>

using namespace std;
typedef long long LL;
char s1[] = "qwertyuiop";
char s2[] = "asdfghjkl;";
char s3[] = "zxcvbnm,./";
char s[105];

int main(){
    char ch;
    scanf("%c", &ch);
    scanf("%s", s);
    int n = strlen(s);

    int n1 = strlen(s1);
    int n2 = strlen(s2);
    int n3 = strlen(s3);
    for(int i = 0; i < n; ++i){
        bool ok = false;
//        cout << s[i];
        for(int j = 0; j < n1; ++j)
            if(s1[j] == s[i]){  cout << (ch == ‘R‘ ? s1[j-1] : s1[j+1]); ok = true; break; }
        if(ok)  continue;
        for(int j = 0; j < n2; ++j)
            if(s2[j] == s[i]){  cout << (ch == ‘R‘ ? s2[j-1] : s2[j+1]);  ok = true; break; }
        if(ok)  continue;
        for(int j = 0; j < n3; ++j)
            if(s3[j] == s[i]){  cout << (ch == ‘R‘ ? s3[j-1] : s3[j+1]); ok = true;  break; }
    }


    return 0;
}

 

CodeForces 474A Keyboard (水题)

标签:

原文地址:http://www.cnblogs.com/dwtfukgv/p/5665137.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!