*1406单词替换

题目链接:http://ybt.ssoier.cn:8088/problem_show.php?pid=1406

 1 #include<string>
 2 #include<cstring>
 3 #include<cstdio>
 4 using namespace std;
 5 int n;
 6 char e,a[150],b[150],s[300][300];
 7 void work(char *w) //参数为指针 
 8 {
 9     string ww=w,vv=a;
10     if(ww==vv)printf("%s ",b);//注意后面有个空格输出
11     /*判断两个字符串是否相等的方法有两种:
12     1.string(a)==string(b) 
13     2.strcmp(a,b) == 0表示相等
14     */ 
15     else printf("%s ",w);//注意后面有个空格输出 
16 }
17 int main()
18 {
19     while(scanf("%s%c",s[++n],&e))
20         if(e!=' ')break;
21     /*读入一行句子的方法:1.利用了scanf的返回值
22                           2.语句结束没有空格
23                           3.巧妙的将单词和空格组成句子 
24                           4.特别注意n的用法记录句子中单词数 
25     */ 
26     scanf("%s%s",a,b);
27     for(int i=1;i<=n;++i)work(s[i]);//注意这儿传递的是地址 
28     return 0;
29  } 
原文地址:https://www.cnblogs.com/tflsnoi/p/8024557.html