PTA 练习 L1-011 A-B (20 分)

版权声明:转载请注明出处,谢谢。 https://blog.csdn.net/Mercury_Lc/article/details/87644872

L1-011 A-B (20 分)

本题要求你计算A−B。不过麻烦的是,A和B都是字符串 —— 即从字符串A中把字符串B所包含的字符全删掉,剩下的字符组成的就是字符串A−B。

输入格式:

输入在2行中先后给出字符串A和B。两字符串的长度都不超过10​4​​,并且保证每个字符串都是由可见的ASCII码和空白字符组成,最后以换行符结束。

输出格式:

在一行中打印出A−B的结果字符串。

输入样例:

I love GPLT!  It's a fun game!
aeiou

输出样例:

I lv GPLT!  It's  fn gm!
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 300005 ;
const int N = 26 ;

char A[200005];
char B[200005];
int t[265];

int main()
{
    scanf("%[^\n]",A);
    getchar();
    scanf("%[^\n]",B);
    int len = strlen(B);
    memset(t,0,sizeof(t));
    for(int i = 0; i < len ; i ++)
    {
        t[B[i]]++;
    }
    int n = strlen(A);
    for(int i = 0; i < n; i ++)
    {
        if(t[A[i]])continue;
        else printf("%c",A[i]);
    }
    printf("\n");

    return 0;
}

猜你喜欢

转载自blog.csdn.net/Mercury_Lc/article/details/87644872