7-3 A-B

 PTA oj 不支持 gets() 函数wa了一发,粗略估计时间复杂度 O(n^2) 应该可以过 又wa 一发, 最后 O(n)时间做,多个

辅助空间的数组,空间复杂度多增加O(n),不过内存是足够的够,小问题。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string a,b,c;
int vis[1000];
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    getline(cin,a);
    getline(cin,b);
    int lena = a.size(), lenb = b.size();

 //   for(int i = 0; i < lena; i++) cout<<a[i];cout<<'
';
//    for(int i = 0; i < lenb; i++) cout<<b[i];cout<<'
';

    for(int i = 0; i < lenb; i++)
    {
        int t = b[i] - 0;
        vis[t] = 1;
    }

    for(int i = 0; i < lena; i++)
    {
        int t = a[i] - 0;
        if(vis[t]) continue;
        else
            c += a[i];
    }
    int len = c.size();
    for(int i = 0; i < len; i++) cout<<c[i];
    cout<<'
';
    return 0;
}

  

原文地址:https://www.cnblogs.com/Edviv/p/12254360.html