zoukankan      html  css  js  c++  java
  • UVA10082-WERTYU(紫书例题3.2)

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

    思路:先将键盘上的键位存储于字符串中,如果匹配的话就输出前一位,空格和换行照样输出;

    #include<iostream>
    #include<algorithm>
    #include<string>
    #include<cmath>
    using namespace std;
    int main()                         
    {                          //先将其存放在字符串中,如果匹配输出前一位 
    	string s="`1234567890-=QWERTYUIOP[]ASDFGHJKL;'ZXCVBNM,./";
    	char c;
    	while((c=getchar())!=EOF)
    	{
    		if(c==' '||c=='
    ')     //如果有空格和换行,照样输出 
    			cout<<c;
    		else
    		{
    		
    			for(int i=1;i<s.length();i++)
    			{
    				if(c==s[i])             //依次寻找匹配 
    					cout<<s[i-1];
    		    }
    		}
    	}
        return 0;
    }
  • 相关阅读:
    Nginx从安装到配置文件详解
    python流程控制语句
    python数据类型以及方法
    python介绍以及基础基础语法
    new 操作符
    js 模拟substr
    js 对于链式加载的思考
    js 实现哈夫曼树
    js实现深度优先
    js 广度优先遍历
  • 原文地址:https://www.cnblogs.com/aerer/p/9931050.html
Copyright © 2011-2022 走看看