1050. String Subtraction (20)

Source: Internet
Author: User

The topics are as follows:

Given-Strings S1 and S2, s = S1-s 2 is defined to being theremaining string after taking all the Charac Ters in S2 from S1. Your task is simply to calculate S1-s2 for any given strings. However, it might is not is, simple-to-do it fast.

Input Specification:

Each input file contains the one test case. Each case consists of lines which gives S1and S 2, respectively. The string lengths of both strings is no more than4. It is guaranteed and a new line character signals the end of the characters is visible ASCII codes and white space of a string.

Output Specification:

For each test case, the print S1-s2 in one line.

Sample Input:
They is Students.aeiou
Sample Output:
Thy R stdnts.


The topic requires the deletion of all characters in the S2 from the string S1, the simplest solution is to S1 with a map of string,s2, and then traverse the output S1, for each character in S1, if there is in the map, it does not output.

Note that the processing of whitespace, using getline (CIN,STR) can read a row, thus implementing string storage with a space string, using the GetChar () function can be used to capture the space and carriage return, the input S2 to map.

The code is as follows:

#include <iostream> #include <string> #include <string.h> #include <stdio.h> #include <map >using namespace Std;int Main () {    string Input,del;    Getline (cin,input);    Map<char,int> STRs;    while (1) {        char c = getchar ();        if (c = = ' \ n ') break;        STRS[C] = 1;    }    for (int i = 0; i < input.length (); i++) {        char c = input[i];        if (Strs.find (c)! = Strs.end ()) continue;        printf ("%c", c);    }    cout << Endl;    return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

1050. String Subtraction (20)

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.