uva_10115_Automatic Editing

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define MAX_RULE        11
#define MAX_CHAR        3001

char   tmp[MAX_CHAR], text[MAX_CHAR];
string find_str[MAX_RULE], replace_str[MAX_RULE];

void replace_str_find_str(int idx, char *p)
{
        // printf("***********************\n");
        // printf("%s\n", text);
        // printf("%s -> %s\n", find_str[idx].c_str(), replace_str[idx].c_str());
        int pos(0);
        for(char *i = text; i != p; i ++) {
                tmp[pos ++] = *i;
        }
        for(int i = 0; i < find_str[idx].length(); i ++, p ++) {
                // tmp[pos ++] = replace_str[idx][i];
        }
        for(int i = 0; i < replace_str[idx].length(); i ++) {
                tmp[pos ++] = replace_str[idx][i];
        }
        for( ; '\0' != *p; p ++) {
                tmp[pos ++] = *p;
        }
        tmp[pos] = '\0'; strcpy(text, tmp); //printf("%s\n", text);
        //printf("***********************\n");
}

void auto_edit(const int &n)
{
        char *p;
        for(int i = 0; i < n; i ++) {
                while( p = strstr(text, find_str[i].c_str()) ) {
                        replace_str_find_str(i, p);
                }
        }
}

int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
        freopen("test.in", "r", stdin);
#endif
        int n;
        while( scanf("%d", &n) && n) { getchar();
                for(int i = 0; i < n; i ++) {
                        gets(tmp); find_str[i].clear(); find_str[i] += tmp;
                        gets(tmp); replace_str[i].clear(); replace_str[i] += tmp;
                }
                gets(text); auto_edit(n); printf("%s\n", text);
        }
        return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值