Analysis of Pat computer problems in Zhejiang University 1050. String subtraction (20)

Source: Internet
Author: User
1050. String subtraction (20) Time limit 10 MS
The memory limit is 32000 kb.
Code length limit: 16000 B
Criterion

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.aeiou

Sample output:

Thy r stdnts.
#include <iostream>#include <string>#include <vector>#include <algorithm>using namespace std;string str1;string str2;string::iterator it1,it2;bool compare(char ch){for (it2=str2.begin();it2!=str2.end();it2++)if (ch == *it2)return true;return false;}int main(){ getline(cin,str1); getline(cin,str2); sort(str2.begin(),str2.end()); str2.erase(unique(str2.begin(),str2.end()),str2.end());str1.resize(remove_if(str1.begin(),str1.end(),compare) - str1.begin()); cout<<str1<<endl;  //system("pause");return 0;}

 
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.