点击链接PAT乙级-AC全解汇总
题目:
旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及实际被输入的文字,请你列出肯定坏掉的那些键。
输入格式:
输入在 2 行中分别给出应该输入的文字、以及实际被输入的文字。每段文字是不超过 80 个字符的串,由字母 A-Z(包括大、小写)、数字 0-9、以及下划线 _(代表空格)组成。题目保证 2 个字符串均非空。
输出格式:
按照发现顺序,在一行中输出坏掉的键。其中英文字母只输出大写,每个坏键只输出一次。题目保证至少有 1 个坏键。
输入样例:
7_This_is_a_test
_hs_s_a_es
- 1
- 2
输出样例:
7TI
- 1
我的代码:
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
int main()
{
char strin[80],strout[80];
cin>>strin>>strout;
int len1=strlen(strin);
int len2=strlen(strout);
int i=0,j=0;
int ascii[128]={0};
bool flag_=true;
for(i=0;i<len1;i++)
{
if(strin[i]==strout[j])j++;
else
{//loss
if(strin[i]>='0'&&strin[i]<='9'&&ascii[(int)strin[i]]!=1)
{//0-9
cout<<strin[i];
ascii[(int)strin[i]]=1;
}
else if(strin[i]>='A'&&strin[i]<='Z'&&ascii[(int)strin[i]]!=1)
{//A-Z
cout<<strin[i];
ascii[(int)strin[i]]=1;
}
else if(strin[i]>='a'&&strin[i]<='z')
{//a-z to A-Z
strin[i]=strin[i]-'a'+'A';
if(ascii[(int)strin[i]]==0)cout<<strin[i];
ascii[(int)strin[i]]=1;
}
else if(strin[i]=='_'&&flag_)
{//_
cout<<'_';
flag_=false;
}
}
}
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
有的时候题目是一起做的,所以会有不需要的头文件
注意空格也算一个按键,不然一个case一直错误
评论记录:
回复评论: