PAT (Basic Level) Practice (中文)1029 旧键盘 (20 分)
2019-07-14 21:33
351 查看
原文链接:http://www.cnblogs.com/shixinzei/p/11185865.html
挨个比较字符,如果主串从串字符相同就同时向后移动一个字符,如果不同就判断当前字符是否出现过 第一次出现就存入输出数组中 然后再移动主串,
重复以上操作,直到把两个串都遍历完[/code]
旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及实际被输入的文字,请你列出肯定坏掉的那些键。
输入格式:
输入在 2 行中分别给出应该输入的文字、以及实际被输入的文字。每段文字是不超过 80 个字符的串,由字母 A-Z(包括大、小写)、数字 0-9、以及下划线
_(代表空格)组成。题目保证 2 个字符串均非空。
输出格式:
按照发现顺序,在一行中输出坏掉的键。其中英文字母只输出大写,每个坏键只输出一次。题目保证至少有 1 个坏键。
输入样例:
7_This_is_a_test _hs_s_a_es
输出样例:
7TI
挨个比较字符,如果主串从串字符相同就同时向后移动一个字符,如果不同就判断当前字符是否出现过 第一次出现就存入输出数组中 然后再移动主串,
重复以上操作,直到把两个串都遍历完[/code]
1 #include <iostream> 2 #include <algorithm> 3 #include <string> 4 #include <cstring> 5 #include <set> 6 using namespace std; 7 string str1,str2; 8 int main() 9 { 10 while(cin>>str1>>str2){ 11 char a[100]; 12 int b[1000]; 13 memset(b,0,sizeof(b)); 14 int len1=str1.length(); 15 int len2=str2.length(); 16 int i=0,j=0,t=0; 17 while(i<len1||j<len2){ 18 if(str1[i]!=str2[j]){ 19 if(str1[i]>='a'&&str1[i]<='z'){ 20 str1[i]-=32; 21 } 22 if(++b[str1[i]]==1){ 23 a[t++]=str1[i]; 24 } 25 i++; 26 }else{ 27 i++; 28 j++; 29 } 30 } 31 for(int i=0;i<t;i++){ 32 cout<<a[i]; 33 } 34 cout<<endl; 35 } 36 return 0; 37 }
转载于:https://www.cnblogs.com/shixinzei/p/11185865.html
相关文章推荐
- PAT (Basic Level) Practise (中文)-1029. 旧键盘(20)
- PAT (Basic Level) Practise (中文)1029. 旧键盘(20)
- PAT (Basic Level) Practise (中文) 1029. 旧键盘(20)
- PAT (Basic Level) Practise (中文)1029. 旧键盘(20) C语言
- PAT (Basic Level) Practise (中文)1029. 旧键盘(20)
- 【PAT】(Basic Level) Practise (中文)1029. 旧键盘(20)
- PAT (Basic Level) Practice 1029 旧键盘(20)(C语言实现)
- PAT (Basic Level) Practise (中文)1029. 旧键盘(20)
- PAT (Basic Level) Practise (中文)1033. 旧键盘打字(20)
- [PTA-PAT]乙级-Basic Level Practice(中文)-1012 数字分类 (20 分)
- PAT (Basic Level) Practise (中文) 1033. 旧键盘打字(20)
- PAT (Basic Level) Practice (中文)1038 统计同成绩学生 (20 分)
- PAT (Basic Level) Practice 1029 旧键盘
- PAT Basic Level 1029 旧键盘 (20 分)
- PAT (Basic Level) Practise (中文)-1033. 旧键盘打字(20)
- PAT(Basic level)Practice 1029 旧键盘 题解
- PAT (Basic Level) Practise (中文)1033. 旧键盘打字(20) C语言
- PAT(basic level) 1029 旧键盘(20)
- Pat(Basic Level)Practice--1029(旧键盘)
- PAT (Basic Level) Practice 1029 旧键盘