题目要求:输入一个字符串,然后在输入一个整数,就是替换字符串的次数,然后依次输入须要替换的字符串……
比如:
输入:asdfghjasdfghj
3
as->bnm
df->qwe
gh->yui
输出:bnmqweyuijbnmqweyuij
意思就是,将输入的字符串中,as替换成bnm,df替换成qwe,gh替换成yui,总共替换三次,注意次数是不限定的,能够是随意整数等。
假设输入的次数是2,举例说明:
输入:asdfgasdfg
2
as->bn
df->yuio
输出:bnyuiogbnyuiog
做完这道题,感觉自己把自己坑了,选择了用C语言,事实上学过Java的同学随便都能够用几行代码实现,耗掉自己非常多时间。
程序实现例如以下:
/*
** Replace String
*/
#include <stdio.h>
#include <string.h>
#define SUCCESS 0
#define FAILED -1
#define MAXLINE 48
#define NOTFOUND -1
int GetNumber(void)
{
char temp;
int count;
count = 0;
temp = getchar();
while(temp >= '0' && temp <= '9')
{
count = count * 10 + (temp - 0x30);
temp = getchar();
}
return count;
}
void GetString(char buff[])
{
char temp;
int i;
i = 0;
temp = getchar();
while (temp != '
')
{
buff[i++] = temp;
temp = getchar();
}
buff[i] = '