UVa10115_Automatic Editing csdn(小白书字符串专题)

解题报告

题意:

替换字符串,一个单词可重复替换

思路:

这种题都很恶心。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
using namespace std;
char str[1000][1000],ch[1000][1000],sh[1000],str1[1000];
int main()
{
    int n,i,j;
    while(~scanf("%d%*c",&n)&&n) {
        memset(str,0,sizeof(str));
        memset(ch,0,sizeof(ch));
        for(i=0; i<n; i++) {
            fgets(str[i],100,stdin);
            int l=strlen(str[i]);
            str[i][l-1]=0;
            fgets(ch[i],100,stdin);
            l=strlen(ch[i]);
            ch[i][l-1]=0;
        }
        fgets(sh,100,stdin);
        int l1=strlen(sh);
        sh[l1-1]=0;
        for(i=0; i<n; i++) {
            while(strstr(sh,str[i])) {
            int l=strlen(str[i]);
                strcpy(str1,sh);
                memset(sh,0,sizeof(sh));
                strncat(sh,str1,strstr(str1,str[i])-str1);
                strcat(sh,ch[i]);
                strcat(sh,strstr(str1,str[i])+l);
            }
        }
        printf("%s\n",sh);
    }
    return 0;
}

Problem E: Automatic Editing

Source file: autoedit.{ccppjavapas}
Input file: autoedit.in
Output file: autoedit.out

Text-processing tools like awk and sed allow you to automatically perform a sequence of editing operations based on a script. For this problem we consider the specific case in which
we want to perform a series of string replacements, within a single line of text, based on a fixed set of rules. Each rule specifies the string to find, and the string to replace it with, as shown below.

Rule Find Replace-by
1. ban bab
2. baba be
3. ana any
4. ba b hind the g

To perform the edits for a given line of text, start with the first rule. Replace the first occurrence of the find string within the text by thereplace-by string, then try to perform
the same replacement again on the new text. Continue until the find string no longer occurs within the text, and then move on to the next rule. Continue until all the rules have been considered. Note that (1) when searching for a findstring,
you always start searching at the beginning of the text, (2) once you have finished using a rule (because the find string no longer occurs) you never use that rule again, and (3) case is significant.

For example, suppose we start with the line

banana boat

and apply these rules. The sequence of transformations is shown below, where occurrences of a find string are underlined and replacements are boldfaced. Note that rule 1 was used twice, then
rule 2 was used once, then rule 3 was used zero times, and then rule 4 was used once.

  Before After
banana boat babana boat
babana boat bababa boat
bababa boat beba boat
beba boat behind the goat

The input contains one or more test cases, followed by a line containing only 0 (zero) that signals the end of the file. Each test case begins with a line containing the number of rules, which will be
between 1 and 10. Each rule is specified by a pair of lines, where the first line is the find string and the second line is the replace-by string. Following all the rules is a line containing the text to edit. For each test case, output a
line containing the final edited text.

Both find and replace-by strings will be at most 80 characters long. Find strings will contain at least one character, but replace-by strings may be empty (indicated
in the input file by an empty line). During the edit process the text may grow as large as 255 characters, but the final output text will be less than 80 characters long.

The first test case in the sample input below corresponds to the example shown above.

Example input:

4
ban
bab
baba
be
ana
any
ba b
hind the g
banana boat
1
t
sh
toe or top
0

Example output:

behind the goat
shoe or shop

UVa10115_Automatic Editing csdn(小白书字符串专题),布布扣,bubuko.com

时间: 2024-12-21 23:37:28

UVa10115_Automatic Editing csdn(小白书字符串专题)的相关文章

UVa10815_Andy&#39;s First Dictionary(小白书字符串专题)

解题报告 思路: 字典树应用,dfs回溯遍历字典树 #include <cstdio> #include <cstring> #include <iostream> using namespace std; struct node { int v; node *next[26]; }; int l,m,cnt; char str[100],ch[100],dic[5500][100]; node *newnode() { int i,j; node *p=new nod

UVa409_Excuses, Excuses!(小白书字符串专题)

解题报告 题意: 找包括单词最多的串.有多个按顺序输出 思路: 字典树爆. #include <cstdio> #include <cstring> #include <iostream> using namespace std; int k,e,num[100],cnt; struct node { int v; node *next[26]; }; node *newnode() { node *p=new node; p->v=0; int i; for(i

UVa10048_Audiophobia(最短路/floyd)(小白书图论专题)

解题报告 题意: 求所有路中最大分贝最小的路. 思路: 类似floyd算法的思想,u->v可以有另外一点k,通过u->k->v来走,拿u->k和k->v的最大值和u->v比较,存下最小的值. #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #define inf 0x3f3f3f3f using namespace std;

UVa10397_Connect the Campus(最小生成树)(小白书图论专题)

解题报告 题目传送门 题意: 使得学校网络互通的最小花费,一些楼的线路已经有了. 思路: 存在的线路当然全都利用那样花费肯定最小,把存在的线路当成花费0,求最小生成树 #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #define inf 0x3f3f3f3f using namespace std; int n,m,_hash[1110][1110],vis

UVa10099_The Tourist Guide(最短路/floyd)(小白书图论专题)

解题报告 题意: 有一个旅游团现在去出游玩,现在有n个城市,m条路.由于每一条路上面规定了最多能够通过的人数,现在想问这个旅游团人数已知的情况下最少需要运送几趟 思路: 求出发点到终点所有路当中最小值最大的那一条路. 求发可能有多种,最短路的松弛方式改掉是一种,最小生成树的解法也是一种(ps,prime和dijs就是这样子类似的) #include <iostream> #include <cstdio> #include <cstring> #include <

UVa10034/POJ2560_Freckles(最小生成树)(小白书图论专题)

解题报告 题意: 把所有点连起来,求使用的墨水最少. 思路: 裸最小生成树. #include <iostream> #include <cstring> #include <cstdio> #include <cmath> #define inf 0x3f3f3f3f using namespace std; struct N { double x,y; } node[110]; int vis[110],n; double mmap[110][110],

UVa10803_Thunder Mountain(最短路)(小白书图论专题)

解题报告 裸floyd. #include <iostream> #include <cstring> #include <cstdio> #include <cmath> #define inf 0x3f3f3f3f using namespace std; int n; double mmap[210][210]; struct node { double x,y; } p[210]; double disc(node p1,node p2) { ret

UVa558_Wormholes(最短路)(小白书图论专题)

解题报告 思路: spfa判负环. #include <iostream> #include <cstring> #include <cstdio> #include <queue> #define inf 0x3f3f3f3f #define N 40000 #define M 100000 using namespace std; struct node { int v,w,next; } edge[M]; int head[N],dis[N],vis[

UVa10806_Dijkstra, Dijkstra.(网络流/费用流)(小白书图论专题)

解题报告 思路: 从s->t 再从t->s等同与s->t两次,要求每条路只能走一次,要求最小花费,让每一条边容量为1,跑跑费用流 只要跑出流量为2就结束. #include <iostream> #include <cstring> #include <cstdio> #include <queue> #define inf 0x3f3f3f3f #define N 5000 #define M 50000 using namespace