POJ 3981(字符串替换)
生活随笔
收集整理的這篇文章主要介紹了
POJ 3981(字符串替换)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
字符串替換
每行數據是一個字符串,長度不超過1000
數據以EOF結束
| Time Limit: 1000MS | ? | Memory Limit: 65536K |
| Total Submissions: 7290 | ? | Accepted: 3451 |
Description
編寫一個C程序實現將字符串中的所有"you"替換成"we"Input
輸入包含多行數據每行數據是一個字符串,長度不超過1000
數據以EOF結束
Output
對于輸入的每一行,輸出替換后的字符串Sample Input
you are what you doSample Output
we are what we do 第一: #include<stdio.h> char str[1002]; int main() { int i; while(gets(str)!=NULL) { i=0;// while(str[i]!='\0')for(i=0;str[i]!='\0';i++) if(str[i]=='y'&&str[i+1]=='o'&&str[i+2]=='u') { printf("we"); i+=2; } else{ printf("%c",str[i]); //i++; } printf("\0");printf("\n");} return 0; } 第二: #include<stdio.h> #include<string.h> char str[1002]; int main() { int i; while(gets(str)!=NULL) { i=0;while(str[i]!='\0') if(str[i]=='y'&&str[i+1]=='o'&&str[i+2]=='u') //短路,可以寫道str[i+2] { printf("we"); i+=3; //printf("%d\n",i);} else{ printf("%c",str[i]); i++; }printf("\0"); //必須是雙引號 printf("\n");} return 0; }?
總結
以上是生活随笔為你收集整理的POJ 3981(字符串替换)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 实战~~整个网络无法浏览,提示网络不存在
- 下一篇: 基于开源流程引擎Activiti5的工作