其他分享
首页 > 其他分享> > 1084 Broken Keyboard (20 分)

1084 Broken Keyboard (20 分)

作者:互联网

1084 Broken Keyboard (20 分)

On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters corresponding to those keys will not appear on screen.

Now given a string that you are supposed to type, and the string that you actually type out, please list those keys which are for sure worn out.

Input Specification:

Each input file contains one test case. For each case, the 1st line contains the original string, and the 2nd line contains the typed-out string. Each string contains no more than 80 characters which are either English letters [A-Z] (case insensitive), digital numbers [0-9], or _ (representing the space). It is guaranteed that both strings are non-empty.

Output Specification:

For each test case, print in one line the keys that are worn out, in the order of being detected. The English letters must be capitalized. Each worn out key must be printed once only. It is guaranteed that there is at least one worn out key.

Sample Input:

7_This_is_a_test
_hs_s_a_es

Sample Output:

7TI

 

题⽬⼤意:旧键盘上坏了⼏个键,于是在敲⼀段⽂字的时候,对应的字符就不会出现。现在给出应该

输⼊的⼀段⽂字、以及实际被输⼊的⽂字,请你列出肯定坏掉的那些键~ ,

题目要求: 如果是字母,必须输出大写。

分析:如果是字母,要同时要标记大小写,其它的按输入的字符串s1的顺序,进行正常比较。

#include<bits/stdc++.h>
using namespace std;
int vis[256];
int main() {
    string s1,s2;
    cin>>s1>>s2;
    char c;
    int j = 0; 
    for( int i=0;i<s1.length();i++){
    	 if( s1[i] !=s2[j]  ){ 
		     if( !vis[s1[i]] ){ 
    	          printf("%c",toupper(s1[i]));
    	 	      c = s1[i];
    	 	 	  vis[c] = 1;
    	 	 	  if( c == '_' || ( c >='0' && c <='9' ) )
    	 	 	        continue;
    	 	 	  else  if( c >='a' && c <= 'z')   
    	 	 	        vis[c-32] = 1;
    	 	 	  else  vis[c+32] = 1;
	         }
	    }
	    else j++;
	} 
    return 0;
}

 

标签:case,1084,20,string,int,contains,worn,Broken,out
来源: https://blog.csdn.net/S_999999/article/details/97642169