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)