【PAT甲级】1084 Broken Keyboard (20 分)
作者:互联网
题意:
输入两行字符串,输出第一行有而第二行没有的字符(对大小写不敏感且全部以大写输出)。
代码:
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
string s1,s2;
bool vis[507];
vector<char>ans;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>s1>>s2;
int n=s1.size();
int p=0;
int pos=0;
for(int i=0;i<n;++i){
if(s1[i]==s2[p])
++p;
else if(!vis[s1[i]-'0']){
if(s1[i]>='a'&&s1[i]<='z')
ans.push_back(s1[i]-'a'+'A');
else
ans.push_back(s1[i]);
vis[s1[i]-'0']=1;
if(s1[i]>='a'&&s1[i]<='z')
vis[s1[i]-'a'+'A'-'0']=1;
else if(s1[i]>='A'&&s1[i]<='Z')
vis[s1[i]-'A'+'a'-'0']=1;
}
if(p==s2.size()){
pos=i+1;
break;
}
}
for(int i=pos;i<n;++i)
if(!vis[s1[i]-'0']){
ans.push_back(s1[i]);
vis[s1[i]-'0']=1;
if(s1[i]>='a'&&s1[i]<='z')
vis[s1[i]-'a'+'A'-'0']=1;
else if(s1[i]>='A'&&s1[i]<='Z')
vis[s1[i]-'A'+'a'-'0']=1;
}
for(auto it:ans)
cout<<it;
return 0;
}
标签:1084,20,vis,int,s2,s1,Broken,&&,ans 来源: https://www.cnblogs.com/ldudxy/p/11877696.html