zoukankan      html  css  js  c++  java
  • 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 }

  • 相关阅读:
    使用RazorGenerator对视图View进行单元测试
    C#常用获取本周、本月、本季度、本年的时间起止段代码
    Redis使用记录
    Git和ConEmu
    mongodb单索引的升序和降序
    AES 加密解密 php c#
    redis 外网连接错误
    .net mvc 分页
    检查Windows上安装的.net版本
    sqlserver跨服务器查询
  • 原文地址:https://www.cnblogs.com/shanyr/p/4712564.html
Copyright © 2011-2022 走看看