asp网站 上传空间,中小企业服务网,安徽建设工程有限公司官网,用wordpress做淘宝客Description 编写一个C程序实现将字符串中的所有you替换成we
Input 输入包含多行数据
每行数据是一个字符串#xff0c;长度不超过1000 数据以EOF结束
Output 对于输入的每一行#xff0c;输出替换后的字符串
Sample Input
you are what you do…Description 编写一个C程序实现将字符串中的所有you替换成we
Input 输入包含多行数据
每行数据是一个字符串长度不超过1000 数据以EOF结束
Output 对于输入的每一行输出替换后的字符串
Sample Input
you are what you do
Sample Output
we are what we do
法一 代码如下
#include iostream
using namespace std;
const int N 1010;
char str[N];int main() {while (gets(str) ! NULL) {for (int i 0; str[i] ! \0; i) {if (str[i] y str[i 1] o str[i 2] u) {printf(we);i i 2;} elseprintf(%c, str[i]);}printf(\n);}return 0;
}法二 代码如下
#include iostream
#include cstdio
using namespace std;int main() {char c1, c2, c3;while ((c1 getchar()) ! EOF) {if (c1 y) {if ((c2 getchar() ) o) {if ((c3 getchar()) u) {printf(we);} elseprintf(yo%c, c3);} elseprintf(y%c, c2);} elseprintf(%c, c1);}return 0;
}法三 代码如下:
#include iostream
#include string
using namespace std;int main() {string str;while (getline(cin, str)) {int pos;while ((pos str.find(you)) ! -1) {str.replace(pos, 3, we);}cout str endl;}return 0;
}