UVa - 10115 - Automatic Editing

来源:互联网 发布:复旦医学院考研 知乎 编辑:程序博客网 时间:2024/06/14 13:24

字符串查找题目 - 注意对string.h中字符串函数的应用

#include<stdio.h>#include<string.h>#define maxn 500char find[15][maxn],replace[15][maxn],str[maxn],temp[maxn];int main(){    int i,len1,len2,n;    char *p;    while(scanf("%d",&n)==1)    {        getchar();        if(n==0) break;        for(i=0;i<n;i++)        {            gets(find[i]);            gets(replace[i]);        }        gets(str);        for(i=0;i<n;i++)        {            len1=strlen(find[i]);            len2=strlen(replace[i]);            while(p=strstr(str,find[i]))            {                strcpy(temp,p+len1);                strcpy(p,replace[i]);                strcpy(p+len2,temp);            }        }        printf("%s\n",str);    }    return 0;}


0 0
原创粉丝点击