码迷,mamicode.com
首页 > 其他好文 > 详细

XidianOJ 1142 删除字符

时间:2016-11-21 12:16:48      阅读:276      评论:0      收藏:0      [点我收藏+]

标签:img   size   turn   class   char   style   ring   拼接   while   

技术分享

--正文

思路是遍历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 删除字符

标签:img   size   turn   class   char   style   ring   拼接   while   

原文地址:http://www.cnblogs.com/ToTOrz/p/6084938.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!