首页 > 代码库 > XidianOJ 1142 删除字符

XidianOJ 1142 删除字符

技术分享

--正文

思路是遍历B,记录出现的字符(反正字符总共就那么几个)

刚开始超时了,因为去用strcat来拼接字符串。但事实上直接输出就好

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

char str[100000];
char str2[100000];
int appear[100000] = {0};
int main(){
    int n;
    while (scanf("%s %s",str,str2) != EOF){
        int len = strlen(str2);
        int i;
        memset(appear,0,sizeof(appear));
        for (i=0;i<len;i++){
            appear[str2[i]] = 1;
        }
        char * now = str;
        bool empty = true;while ( *now != \0){
            if (appear[*now]) {
            }
            else {
                empty = false;
                printf("%c",*now);    
            }
            now ++;
        }    
        if (empty) {
            printf("EMPTY\n");
            continue;
        }
        printf("\n");
    }

    return 0;
}

 

XidianOJ 1142 删除字符