标签:cout namespace end turn 之间 help ros space size
输入一个字符串,以回车结束(字符串长度<=100)。该字符串由若干个单词组成,单词之间用一个空格隔开,所有单词区分大小写。现需要将其中的某个单词替换成另一个单词,并输出替换之后的字符串。
You want someone to help you You I
I want someone to help you
#include<iostream> #include<cstring> using namespace std; int main(){ char s[100],a[100],b[100]; while(gets(s)){ gets(a); gets(b); int flag=1; char *temp=strtok(s," "); while(temp){ if(flag) flag=0; else cout<<" "; if(strcmp(temp,a)==0) cout<<b; else cout<<temp; temp=strtok(NULL," "); } cout<<endl; } return 0; }
标签:cout namespace end turn 之间 help ros space size
原文地址:https://www.cnblogs.com/bernieloveslife/p/9735001.html