you are what you do
we are what we do
错误思路:
#include<cstdio> #include<cstring> char str[1010]; char s[1010][1010]; int main() { char s1[5]="you"; char s2[5]="we"; int len,i,j=0,k=0; gets(str); len=strlen(str); for(i=0;i<=len;i++) { if(str[i]==' '||str[i]=='\0') { s[k][j]='\0'; k++; j=0; } else { s[k][j++]=str[i]; } } i=0; if(i==0) { if(strcmp(s[i],s1)==0) printf("%s",s2); else printf("%s",s[i]); } for(i=1;i<k;i++) { if(strcmp(s[i],s1)==0) printf(" %s",s2); else printf(" %s",s[i]); } return 0; }
正确代码:
<pre name="code" class="cpp">#include<stdio.h> #include<string.h> int main() { char a[1010]; int i; while(gets(a)){ int len=strlen(a); int j=0,k=0; for(i=0;i<len;i++) { if(a[i]=='y'&&a[i+1]=='o'&&a[i+2]=='u') { printf("we"); i=i+2; } else printf("%c",a[i]); } printf("\n"); } return 0; }
原文地址:http://blog.csdn.net/holyang_1013197377/article/details/39433759