• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
dwtfukgv
博客园    首页    新随笔    联系   管理    订阅  订阅
CodeForces 474A Keyboard (水题)

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

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

代码如下:

#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;
}

 

posted on 2016-07-12 22:28  dwtfukgv  阅读(351)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3