如何用C或者C++编程实现“查找与替换”问题?

来源:百度知道 编辑:UC知道 时间:2024/05/22 06:10:23
问题描述:
一些编缉器都有查找和替换的功能,使用起来非常方便,可以对一些相同的情况进行统一的处理,我们现在要使用的查找、替换比那容易的多。举个例子,给定一个文本S为”ararast”,需要替换的字符串T为”ara”,要替换成的字符串RE为”ra”,从头开始查找文本S中是否含有字符串T,当查找成功时,你只需要把相应的字符串用RE代替,然后处理后面的字符串,不用担心新的文本中是否含有需要替换的字符串,像上例中,当查找到S中含有”ara”时,需要把”ara”替换成”ra”,然后再处理后面的字符串”rast”,但中间已经不含需要替换的字符串,因此最后得到的文本为”rarast”。
Input
输入数据的第一行为一个整数n,(0 < n ≤ 100),表示测试数据的个数,第2行到第n + 1行为n组测试数据,其中每一行包括上面描述的三个字符串S,T,RE,字符串中仅含有小写字母,其中0 < |S| ≤ 10000,0 < |T| ≤ 10, 0 < |re| ≤ 10;
Output
输出替换后最终得到的字符串
Sample Input:
2
ararast ara ra
abcdabcd a aa

Sample Output:
rarast
aabcdaabcd
答案请发我邮箱: ljj0217@126.com 谢谢大家! 答案可行的话追加100分!绝不食言!

#include "stdio.h"
#include "stdlib.h"
#include "string.h"
int shoudsave=0; /* */
struct student
{
char num[10];/* 学号 */
char name[20];
char sex[4];
int cgrade;
int mgrade;
int egrade;
int totle;
int ave;
char neartime[10];/* 最近更新时间 */
};

typedef struct node
{
struct student data;
struct node *next;
}Node,*Link;

void menu()
{
printf("********************************************************************************");
printf("\t1登记学生资料\t\t\t\t\t2删除学生资料\n");
printf("\t3查询学生资料\t\t\t\t\t4修改学生资料\n");
printf("\t5保存学生资料\t\t\t\t\t0退出系统\n");
printf("********************************************************************************\n");
}

voi