[PAT解题报告] String Subtraction

从字符串1中删掉字符串2中全部的字符。
简单题,我们可以用hash,或者bitmap把字符串2中全部的字符保存下来,其实bool数组就可以了,反正C/C++一共就256种字符。

代码:
#include <cstring>
#include <string>
#include <cstdio>
using namespace std;

char s1[10004],s2[10004];

bool mark[256];

int main() {
    gets(s1);
    gets(s2);
    for (char *t = s2; *t; ++t) {
        mark[*t] = true;
    }
    for (char *t = s1; *t; ++t) {
        if (!mark[*t]) {
            putchar(*t);
        }
    }
    puts("");
    return 0;
}
原题链接: http://www.patest.cn/contests/pat-a-practise/1050
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务