poj 2538(簡單題)

來源:互聯網
上載者:User

題意是一個錯誤的鍵盤,輸入的一個字母或字元時會變成這個字母或字元在鍵盤上位置右邊的一個。 然後已知輸出的字元,求你原本輸入的是什麼。

有一種很土的辦法就是一個字元一個字元的裝換,但是這樣不知道要用多少個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

Waterloo local 2001.01.27 

 

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

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.