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

题意:

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

trick:

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

AAAAAccepted code:

 1 #define HAVE_STRUCT_TIMESPEC
 2 #include<bits/stdc++.h>
 3 using namespace std;
 4 char s1[10007],s2[10007];
 5 int vis[507];
 6 int main(){
 7     ios::sync_with_stdio(false);
 8     cin.tie(NULL);
 9     cout.tie(NULL);
10     cin.getline(s1,10005);
11     cin.getline(s2,10005);
12     int n=strlen(s1);
13     int m=strlen(s2);
14     for(int i=0;i<m;++i)
15         vis[s2[i]-NULL]=1;
16     for(int i=0;i<n;++i)
17         if(!vis[s1[i]-NULL])
18             cout<<s1[i];
19     return 0;
20 }

 

 

 

posted @ 2019-10-02 10:09  sewage  阅读(201)  评论(0编辑  收藏  举报