Topic 1049 string to specific character 9 degree Online Judge
Description:
The input string s and character c must be removed from all the c characters in s and output results.
Input:
There are multiple groups of test data, with each group of input strings s and character c.
Output:
For each group of inputs, the output results after the c characters are removed.
Sample input:
healloa
Sample output:
hello
Method 1:
# Include
# Include
Using namespace std; int main () {string s; // ×ö· û'®While (cin> s) {char c; cin> c; for (int I = 0; I <s. length (); I ++) {if (s [I]! = C) {cout <
Method 2:
/* This idea: compare two string arrays. If the two strings are the same, replace them with a specific character. Because it is a string, it is special, so choose to replace it with '\ n! The question is why we use getline when we try again. The result displayed for the first time is correct. It is incorrect when we perform the second test! If you are interested, try it on your own. */# Include
# Include
Using namespace std; int main () {string str1, str2; int I, j; // while (cin, str1) while (cin> str1) {int x = I; // getline (cin, str2); // I don't know why. When getline is used in the while loop, the first comparison is correct. The second comparison is incorrect! // If Daniel knows, please let me know! Cin> str2; for (int I = 0; I