题目链接:点击打开链接
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.我的C++程序:
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
int i = 0,j=0;
string s1, s2;
vector<bool>not_exist(1000,true);
getline(cin, s1);//s1,s2可能含有空格所以用getline()
getline(cin, s2);
for (i = 0;i < s2.size();i++)
{
not_exist[s2[i]] = false;//记录s2存在的字符
}
for (i = 0;i < s1.size();i++)
{
if (not_exist[s1[i]] == true)//输出s1里不含s2的字符
printf("%c", s1[i]);
}
//system("pause");
return 0;
}
本文介绍了一个简单的字符串处理问题,即如何快速计算两个字符串S1和S2的差集S1-S2,通过示例和C++代码展示了具体的实现方法。
911

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



