• WERTYU(getchar()用法)


    题目连接:http://acm.tju.edu.cn/toj/showp.php?pid=1368
    1368.   WERTYU
    Time Limit: 1.0 Seconds   Memory Limit: 65536K
    Total Runs: 3158   Accepted Runs: 1346



    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 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. 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/
    

    Output for Sample Input

    I AM FINE TODAY.
    



    Source: Waterloo Local Contest Jan. 17, 2001

    题解:一个水题却教会了我如何使用getchar(), 在所有的读入数据的时候都是在没打回车之前数据存在缓存中,回车后开始将缓存中的数据读入到程序中,所以这个题,可以一个一个获取每个字符,然后处理,然后输出

    代码中还有个细节就是是一个转移字符,而\表示的是一个代表的字符,它只占一个char的空间

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<string>
     4 #include<cstring>
     5 #include<algorithm>
     6 using namespace std;
     7 
     8 int main()
     9 {
    10     char s[80] = "`1234567890-=QWERTYUIOP[]\ASDFGHJKL;'ZXCVBNM,./0";
    11     int i , c;
    12     while((c = getchar())!=EOF)
    13     {
    14         int i;
    15         for( i = 0 ;i < strlen(s) ;i++)
    16         {
    17             if(s[i]==c){ printf("%c",s[i-1]); break ;}
    18         }
    19         if(i==strlen(s)) printf("%c", c);
    20     }
    21     return 0;
    22 }

  • 相关阅读:
    ScottGu: 宣布微软 AJAX CDN
    表格数据流协议TDS
    .NET 4 System.Threading.Barrier 类
    企业架构思考
    OpenSSL的托管项目
    WCF服务中操作FormsAuthentication的Cookie
    Silverlight相关博客收集20090927
    Sync Framework 2.0
    [中央电视台·见证]大学堂——兰州大学
    系统进程管理工具Process Explorer
  • 原文地址:https://www.cnblogs.com/shanyr/p/4712564.html
Copyright © 2020-2023  润新知