【PAT甲级】1050 String Subtraction (20 分)

题意:

输入两个串,长度小于10000,输出第一个串去掉第二个串含有的字符的余串。

trick:

ascii码为0的是NULL,减去'0','a','A',均会导致可能减成负数。

代码:

#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
char s1[10007],s2[10007];
int vis[507];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin.getline(s1,10005);
cin.getline(s2,10005);
int n=strlen(s1);
int m=strlen(s2);
for(int i=0;i<m;++i)
vis[s2[i]-NULL]=1;
for(int i=0;i<n;++i)
if(!vis[s1[i]-NULL])
cout<<s1[i];
return 0;
}

猜你喜欢

转载自www.cnblogs.com/ldudxy/p/11616884.html