UVa 10115 - Automatic Editing

题目:给你一些字符串的替换关系,以及一个句子。按顺序替换,输出最后结果。

分析:字符串。按照替换顺序依次替换(这个替换用过之后,就不再使用),每个替换可能出现多次。

这里注意,如果当前串中有多个可被当前单词替换的位置,只替换最前面的那个,

下次用本次生成的串替换,而不是整体一次性替换。

说明:注意数据清空。

#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>

using namespace std;

char word1[20][84];
char word2[20][84];
char texts[260];

/* 寻找单词 */
int find_word( char *a, char *b )
{
	for ( int i = 0 ; a[i] ; ++ i )
		if ( a[i] != b[i] )
			return 0;
	return 1;
}
/* 替换单词 */
void replace_word( char *a, int id )
{
	char buf[256];
	memset( buf, 0, sizeof(buf) );
	int move = 0,save = 0;
	while ( a[move] ) {
		if ( find_word( word1[id], a+move ) ) {
			strcpy( buf+save, word2[id] );
			move += strlen(word1[id]);
			save += strlen(word2[id]);
			break;
		}else buf[save ++] = a[move ++];
	}
	while ( a[move] )
		buf[save ++] = a[move ++];
	strcpy( a, buf );
}

int main()
{
	int n;
	while ( ~scanf("%d",&n) && n ) {
		getchar();
		for ( int i = 0 ; i < n ; ++ i ) {
			gets(word1[i]);
			gets(word2[i]);
		}
		gets(texts);

		for ( int i = 0 ; i < n ; ++ i )
		for ( int j = 0 ; j < 260 ; ++ j )
			replace_word( texts, i );
		printf("%s\n",texts);
	}
	return 0;
}

UVa 10115 - Automatic Editing,布布扣,bubuko.com

时间: 2024-12-21 03:53:23

UVa 10115 - Automatic Editing的相关文章

UVA 10115 Automatic Editing(字符处理)

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

Automatic Editing UVA 10115

#include <stdio.h> #include <string.h> #define MAXL 225+5 #define MAXN 10+5 char find[MAXN][MAXL],replace[MAXN][MAXL]; char text[MAXL],convert[MAXL]; int Find(int,int*); void Replace(int,int); int str_cmp(int,int); int main(){ int N,i,j,k; int

UVa 10361 Automatic Poetry

Automatic Poetry Input: standard input Output: standard output Time Limit: 2 seconds Memory Limit: 32 MB “Oh God”, Lara Croft exclaims, “it’s one of these dumb riddles again!” In Tomb Raider XIV, Lara is, as ever, gunning her way through ancient Egyp

小白书训练-Automatic Editing

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1056 题意:替换单词,这个题不难,但写题解想想就是泪啊TAT,最大要注意的地方就是要替换彻底,就是替换完之后如果可以替换接着替换,其次,一定要一个单词一个单词的替换. 剩下的看代码吧: #include <iostream> #include <stdio.h&g

UVA 10115 子符串替换

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

POJ1572 Automatic Editing 字符串替换,replace就够了

题意不难理解,但是一开始还是没有看清楚题目.Replace the first occurrence of the find string within the text by the replace-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

【UVa】11212 Editing a Book(IDA*)

题目 题目 ? ? 分析 get一下IDA*的技巧,感觉总体来说不难,主要是剪枝比较难想. 这是lrj的代码,比较通俗易懂,关键就是选定一个区间再取出来,插入到一个位置,接下来转移到这个状态. ? ? 代码 #include <bits/stdc++.h> using namespace std; const int maxn=10; int n,a[maxn]; bool is_sorted() { for(int i=0;i<n-1;i++) if(a[i]>=a[i+1])

UVA题目分类

题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494 - Kindergarten Counting Game 414 - Machined Surfaces 490 - Rotating Sentences 445 - Marvelous Mazes

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("