1. 程式人生 > >PAT甲級-1050 String Subtraction(water)

PAT甲級-1050 String Subtraction(water)

1050 String Subtraction (20 分)

Given two strings S​1​​ and S​2​​, S=S​1​​−S​2​​ is defined to be the remaining string after taking all the characters in S​2​​ from S​1​​. Your task is simply to calculate S​1​​−S​2​​ for any given strings. However, it might not be that simple to do it fast.

Input Specification:

Each input file contains one test case. Each case consists of two lines which gives S​1​​ and S​2​​, respectively. The string lengths of both strings are no more than 10​4​​. It is guaranteed that all the characters are visible ASCII codes and white space, and a new line character signals the end of a string.

Output Specification:

For each test case, print S​1​​−S​2​​ in one line.

Sample Input:

They are students.
aeiou

Sample Output:

Thy r stdnts.

//題意:給你兩個字串s1,s2;要求輸出s3(s1減去s2中出現的字母);

//注意點:pta的oj不支援gets();

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
int mark[10000];
int main()
{
    memset(mark,0,sizeof(mark));
    string ss1,ss2;
    getline(cin,ss1);
    getline(cin,ss2);
    char s1[10005],s2[10005];
    int i;
    for(i=0;i<ss1.size();i++)s1[i]=ss1[i];
    s1[i]='\0';//這步別忘了
    for(i=0;i<ss2.size();i++)s2[i]=ss2[i];
    s2[i]='\0';
    for(i=0;i<strlen(s2);i++)
    {
        int temp=s2[i];
        mark[temp]=1;
    }
    for(i=0;i<strlen(s1);i++)
    {
        int temp=s1[i];
        if(mark[temp]==0)
            printf("%c",s1[i]);
    }
    return 0;
}