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

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

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

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

说明:注意数据清空。

#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相关推荐

  1. UVA 10115 Automatic Editing (字符串的替换和查找)

    分析:水题,熟悉字符串的find和replace函数便可轻易解决 好久每一1A的题了,UVA的格式要求真是醉了,每次都得调试半天格式 #include <cstdio> #include ...

  2. UVA 10115 Automatic Editing

    字符串函数的应用. # include <cstdio> # include <cstring># define RULESN 10 + 5 # define MAXLEN 8 ...

  3. uva 10115(字符串)

    题目: Text-processing tools like awk and sed allow you to automatically perform a sequence of editing ...

  4. UVa 10115 自动编辑

    /* * 解题思路: * 题意虽不难理解.但一定要读清楚! *      它匹配过程中.是允许一个字符串重复匹配上一个字符串的.就好比说例子 banana boat , 在bab匹配ban的过程中 * ...

  5. uva-10115 - Automatic Editing

    不得不说,这道题目还是比较麻烦的.但是不难,仔细一点做,绝对不会错的. 题目的意思也和简单,就是先给你一个数N,然后给你N组字符串,每组都有两行,第一行是原本的字符串yuan[i],另一组是替换的 字 ...

  6. UVA-10115 Automatic Editing

    原题链接: https://vjudge.net/problem/UVA-10115#author=Luke AC代码: #include <bits/stdc++.h> using na ...

  7. 提取了下刘汝佳推荐的题号...

    今天闲来没事上uva oj提取了下刘汝佳推荐的acm题号,原始数据如下: Volume 0. Getting Started    10055 - Hashmat the Brave Warrior ...

  8. ajax如何做到异步交互,1.ajax简单实现异步交互

    效果:点击获取信息 testAjax.jsp: pageEncoding="UTF-8"%> Insert title here function getName(){ va ...

  9. TYUT-A专题题解(一)

    TYUT-A专题题解(一) 01A Ad Hoc UVA353 LA5247 Pesky Palindromes[回文] - 海岛Blog - CSDN博客 UVA947 Master Mind He ...

最新文章

  1. 谷歌启动搜索引擎新功能 网页Flash内容即时预览
  2. WatchDog工作原理
  3. JAVA中的适配器应用_Java适配器模式应用之电源适配器功能详解
  4. 关闭mysql权限管理_MySQL系列:用户及权限管理
  5. 无需写代码!谷歌推出机器学习模型分析神器,代号What-If
  6. CentOS6.8 x86_64bit安装nginx-1.6.2
  7. ADSL拨号网络环境下实时视频广播的完美实现
  8. python下载的库包放_python下载的库包存放路径
  9. i3处理器_办公笔记本i3够用了吗
  10. 超全蓝牙芯片原厂总结(含芯片型号)
  11. Flash Programer 给CC2530下载Hex文件 error解决办法 汇总
  12. 点击超链接弹出QQ对话窗口
  13. [bzoj1127][悬线法]KUP
  14. Pdf 插入图片 | 指定位置插入图片 不改变原格式 直接操作 pdf
  15. Window Server 2008虚拟机安装
  16. 三阶行列式简便算法_三阶行列式是什么?如何计算?
  17. 使用计算机编辑文档的同时,小学信息技术2-2-用计算机编辑文档(北京版).doc
  18. 天人感应和小概率事件
  19. 2021春招BAT面试真题详解,etl开发工程师简历模板
  20. 【基础算法】开平方算法 C++实现

热门文章

  1. Franklin-Reiter相关消息攻击
  2. mysql int 11 最大多少_MySQL中int(11)最大长度是多少?
  3. linux 上端口占用的程序
  4. NPN求解三极管电路或电容恒流放电详解,三极管工作在放大区,基极控制集电极电流,针对电荷泵电容恒流放电控制,因为电荷泵输出恒定电流给快充手机锂电池充电
  5. 护眼台灯什么价位的好?五百元内适合学生党的护眼台灯
  6. Spring Boot 整合——Spring batch重试和回滚
  7. React构造函数中为什么要写 super(props)
  8. vs2019生成dll文件及(C#)使用
  9. Ableton Live 11 Suite v11.1.0 WiN-MAC 电音制作宿主软件
  10. java日志体系分析