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.
Enter 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 only 1 rows per test data output, replacing all word a in s with the string after B.
Sample input
I Love Tian Qin
I
You
Sample output
You love Tian Qin
hint [+]
Tip is hidden, click above [+] to show * * *
Source
2007 Peking University computer Research Life Test real problem
/*********************************
* Date: 2013-4-5
* Author: SJF0115
* title number: Title 1159: Word Substitution
* Source: http://acmclub.com/problem.php?id=1159
* Result: AC
* Source: Tian Qin OJ
* Summary:
****** /
#include <stdio.h>
#include <stdlib.h>
#include < string.h>
int main ()
{
int i,j,index,len,len2;
Char str[101],word[101],newword[101],temp[101];
Freopen ("C:\\users\\sjf\\desktop\\acm.txt", "R", stdin);
while (gets (str)) {
index = 0;
len = strlen (str);
scanf ("%s", word);
scanf ("%s", Newword);
for (i = 0;i <= len;i++) {
if (str[i] = = "| | i = len) {
Temp[index] = ' + ';
if (strcmp (temp,word) = = 0) {
printf ("%s", Newword);
}
else{
printf ("%s", temp);
}
if (str[i] = = ") {
printf (" ");
}
else{
printf ("\ n");
}
index = 0;
memset (temp,0,sizeof (temp));
}
else{
temp[index++] = Str[i];
}
}
GetChar ();
}
return 0;
}