1050. String Subtraction (20)
Given two strings S1 and S2, S = S1 - S2 is defined to be the remaining string after taking all the characters in S2 from S1. Your task is simply to calculate S1 - S2 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 S1 and S2, respectively. The string lengths of both strings are no more than 104. 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 S1 - S2 in one line.
Sample Input:They are students. aeiouSample Output:
Thy r stdnts.
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <stack>
using namespace std;
int book[10000]={0};
int main()
{
freopen("in.txt","r",stdin);
char a[11000];
char b[11000];
gets(a);//读入带空格的字符串
gets(b);
int len1=strlen(a);//strlen获取字符串长度
int len2=strlen(b);
int i;
cout<<len1<<' '<<len2;
/*
for(i=0;i<len2;i++)
{
int t;
t=b[i];
book[t]=1;
}
for(i=0;i<len1;i++)
{
int t2;
t2=a[i];
if(book[t2]==1)
{
continue;
}
else
{
printf("%c",a[i]);
}
}
*/
return 0;
}
本文介绍了一个简单的字符串减法问题:给定两个字符串S1和S2,如何快速地计算出S1-S2的结果,即去除S1中所有出现在S2中的字符。输入包括两个字符串,输出为处理后的结果。
385

被折叠的 条评论
为什么被折叠?



