zoukankan      html  css  js  c++  java
  • poj 2538(简单题)

    题意是一个错误的键盘,输入的一个字母或字符时会变成这个字母或字符在键盘上位置右边的一个。 然后已知输出的字符,求你原本输入的是什么。

    有一种很土的办法就是一个字符一个字符的装换,但是这样不知道要用多少个if。

    可以把这这些字符存在一起 g[1000] ={"1234567890-=QWERTYUIOP[]\ASDFGHJKL;'ZXCVBNM,./"} ,这样只要找到了一个字符在这个g串中的位置i,然后g[i-1]就是我们要的哪个字符。 这样编程量就少了很多

    WERTYU
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 7513   Accepted: 3538

    Description

     
    A common typing error is to place the hands on the keyboard one row to the right of the correct position. So "Q" is typed as "W" and "J" is typed as "K" and so on. You are to decode a message typed in this manner.

    Input

    Input consists of several lines of text. Each line may contain digits, spaces, upper case letters (except Q, A, Z), or punctuation shown above [except back-quote (`)]. Keys labelled with words [Tab, BackSp, Control, etc.] are not represented in the input.

    Output

    You are to replace each letter or punctuation symbol by the one immediately to its left on the QWERTY keyboard shown above. Spaces in the input should be echoed in the output. 

    Sample Input

    O S, GOMR YPFSU/
    

    Sample Output

    I AM FINE TODAY.
    

    Source

     
    #include <stdio.h>
    #include <string.h>
    #include <iostream>
    using namespace std;
    
    char str[1100];
    char g[1100]={"1234567890-=QWERTYUIOP[]\ASDFGHJKL;'ZXCVBNM,./"};
    
    int main()
    {
        while(gets(str)!=0)
        {
            
            int len=strlen(str);
            for(int i=0;i<len;i++)
            {
                char tmp=str[i];
                int j;
                for(j=0;j<1100;j++)
                {
                    if(g[j]==tmp)
                        break;
                }
                if(j==1100) printf("%c",tmp);
                else
                printf("%c",g[j-1]);
            }
            printf("\n");
        }
        return 0;
    }
  • 相关阅读:
    C#快速随机按行读取大型文本文件
    OpenReadWithHttps
    fiddler不能监听 localhost和 127.0.0.1的问题 .
    C#放缩、截取、合并图片并生成高质量新图的类
    JS判断只能是数字和小数点
    HTML5 Support In Visual Studio 2010
    GridView 获取列字段的几种途径
    微信朋友圈如何同时分享(图片+文字) Android版
    【Android】 PopupWindow使用小结
    Android 第三方应用接入微信平台(2)
  • 原文地址:https://www.cnblogs.com/chenhuan001/p/2990708.html
Copyright © 2011-2022 走看看