-
Title Description:
-
Enter a string to end with a carriage return (string length <=100). The string consists of several words, separated by a space, and all the words are case-sensitive. Now you need to replace one of these words with another word and output the replaced string.
-
Input:
-
Multiple sets of data. Each set of data input consists of 3 rows, the 1th line is a string with multiple words, the 2nd line is the word a to be replaced, and (length <=100) line 3rd is the word b that will be replaced. (length <=100) s, a, b the front and the back have no spaces.
-
Output:
-
Each test data output has only 1 rows, replacing all word a in s with the string after B.
-
Sample input:
-
Want someone to help Youyoui
-
Sample output:
-
I want someone to help you
#include <iostream>#include<cstring>using namespacestd;intMain () {Chars[ -],a[ -],b[ -]; while(gets (s)) {gets (a); Gets (b); intflag=1; Char*temp=strtok (s)," "); while(temp) {if(flag) flag=0; Elsecout<<" "; if(strcmp (temp,a) = =0) cout<<b; Elsecout<<temp; Temp=strtok (NULL," "); } cout<<Endl; } return 0;}
1111. Application of Word substitution strtok function