uva-10115 - Automatic Editing

uva-10115 - Automatic Editing

题目大意:先给你一个数N,然后给你N组字符串,每组都有两行,第一行是原本的字符串,另一组是替换的
字符串,之后给定一串字符串,如果这个字符串的字串符合,那么就用替换的串来替换原来的串
解题思路,利用strstr,strcpy,strcat三个很容易做出来

#include<cstdio>
#include<cstring>

char map[1000][1000];
char major[1000];
char* solve(char*major,char*map1,char*map2)
{
    char temp[1000];
    char*t;
    while(strstr(major,map1))
    {
        t=strstr(major,map1);
        t[0]='\0';
        strcpy(temp,major);
        strcat(temp,map2);
        t+=strlen(map1);
        strcat(temp,t);
        strcpy(major,temp);
    }
    return major;
}
int main(){
    int c;
    while(scanf("%d",&c)&&c)
    {
        getchar();
        for(int i = 0; i < 2*c ;i+=2)
        {
            gets(map[i]);
            gets(map[i+1]);
        }
        gets(major);
        for(int i=0;i<2*c;i+=2)
            solve(major,map[i],map[i+1]);
        printf("%s\n",major);
   }

    return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值