He made each turtle stand on another one’s back
And he piled them all up in a nine-turtle stack.
And then Yertle climbed up. He sat down on the pile.
What a wonderful view! He could see ’most a mile!
    King Yertle wishes to rearrange his turtle throne to place his highest-ranking nobles and closest advisors nearer to the top. A single operation is available to change the order of the turtles in the stack: a turtle can crawl out of its position in the stack and climb up over the other turtles to sit on the top.
    Given an original ordering of a turtle stack and a required ordering for the same turtle stack, your job is to determine a minimal sequence of operations that rearranges the original stack into the required stack.
Input
The first line of the input consists of a single integer K giving the number of test cases. Each test case consist on an integer n giving the number of turtles in the stack. The next n lines specify the original ordering of the turtle stack. Each of the lines contains the name of a turtle, starting with the turtle on the top of the stack and working down to the turtle at the bottom of the stack. Turtles have unique names, each of which is a string of no more than eighty characters drawn from a character set consisting of the alphanumeric characters, the space character and the period (‘.’). The next n lines in the input gives the desired ordering of the stack, once again by naming turtles from top to bottom. Each test case consists of exactly 2n + 1 lines in total. The number of turtles (n) will be less than or equal to two hundred.
Output
For each test case, the output consists of a sequence of turtle names, one per line, indicating the order in which turtles are to leave their positions in the stack and crawl to the top. This sequence of operations should transform the original stack into the required stack and should be as short as possible. If more than one solution of shortest length is possible, any of the solutions may be reported.
    Print a blank line after each test case.
Sample Input
2
3
Yertle
Duke of Earl
Sir Lancelot
Duke of Earl
Yertle
Sir Lancelot
9
Yertle
Duke of Earl
Sir Lancelot
Elizabeth Windsor
Michael Eisner
Richard M. Nixon
Mr. Rogers
Ford Perfect
Mack
Yertle
Richard M. Nixon
Sir Lancelot
Duke of Earl
Elizabeth Windsor
Michael Eisner
Mr. Rogers
Ford Perfect
Mack
Sample Output
Duke of Earl
Sir Lancelot
Richard M. Nixon
Yertle

问题链接:UVA10152 ShellSort
问题简述:(略)
问题分析
    原始给定若干个字符串(字符串序列),另外给定这些字符串的要求顺序(也是字符串序列),可以做的操作是从中取出一个字符放到最前面,计算需要移动哪些字符串,使得字符串顺序调整为要求的顺序。
    将目标字符串从后往前与原始给定字符串进行匹配(也是从后往前),不能顺序匹配的那些字符串即为需要移动的字符串。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA10152 ShellSort */#include <bits/stdc++.h>using namespace std;const int N = 256;
char s[N][N], t[N][N];int main()
{int k, n;scanf("%d", &k);while(k--) {scanf("%d", &n);getchar();for(int i = 0; i < n; i++)gets(s[i]);for(int i = 0; i < n; i++)gets(t[i]);int p = n - 1, q = n - 1;while(p >= 0) {if(!strcmp(t[q], s[p])) q--;p--;}while(q >= 0)printf("%s\n", t[q--]);printf("\n");}return 0;
}

UVA10152 ShellSort【匹配】相关推荐

  1. Competitive Programming 3题解

    题目一览: Competitive Programming 3: The New Lower Bound of Programming Contests(1) Competitive Programm ...

  2. AOAPC I: Beginning Algorithm Contests 题解

    AOAPC I: Beginning Algorithm Contests 题解 AOAPC I: Beginning Algorithm Contests (Rujia Liu) - Virtual ...

  3. ICPC程序设计题解书籍系列之八:(美)斯基纳等:《挑战编程-程序设计竞赛训练手册》

    S书<挑战编程--程序设计竞赛训练手册>题目一览 1 Getting Started UVA100 POJ1207 HDU1032 The 3n + 1 problem[水题] - 海岛B ...

  4. python数据结构和算法 时间复杂度分析 乱序单词检测 线性数据结构 栈stack 字符匹配 表达式求值 queue队列 链表 递归 动态规划 排序和搜索 树 图

    python数据结构和算法 参考 本文github 计算机科学是解决问题的研究.计算机科学使用抽象作为表示过程和数据的工具.抽象的数据类型允许程序员通过隐藏数据的细节来管理问题领域的复杂性.Pytho ...

  5. re2正则表达式匹配引擎的c接口版本cre2的中文使用手册

    前言 re2 官方地址: https://github.com/google/re2 cre2 官方地址: https://github.com/marcomaggi/cre2 1 基本类型定义 不透 ...

  6. LeetCode简单题之统计匹配检索规则的物品数量

    题目 给你一个数组 items ,其中 items[i] = [typei, colori, namei] ,描述第 i 件物品的类型.颜色以及名称. 另给你一条由两个字符串 ruleKey 和 ru ...

  7. 深度树匹配模型(TDM)

    深度树匹配模型(TDM) 算法介绍 Tree-based Deep Match(TDM)是由阿里妈妈精准定向广告算法团队自主研发,基于深度学习上的大规模(千万级+)推荐系统算法框架.在大规模推荐系统的 ...

  8. php 正则中文匹配

    汉字一定注意是gbk还是utf8编码 UTF-8匹配:在javascript中,要判定字符串是中文是很简朴的.比如:var str = "php编程";if (/^[\u4e00- ...

  9. [JS][编程题]括号匹配

    括号匹配 题目来源:牛客网 题目链接:括号匹配 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M 题目描述 给定一个只包含括号的字符串,判断字符串是否有效.其 ...

最新文章

  1. 高德地图天气图标符号大全_共享雨伞,高德这波营销格外暖!
  2. python读awx文件_ansible awx用法
  3. Iirf安装配置(图文)
  4. 构建数据库云管平台 实现数据价值最大化
  5. SprinBoot-data-jpa整合Vue使用Swagger2实现前后端分离
  6. rocketmq 重复消费_消息队列 RocketMQ
  7. sql azure 语法_如何将SQL数据迁移到Azure Cosmos DB
  8. 使用Enide Studio 2014 IDE来表达JS WebApplication
  9. SpringBoot Starter自动装配的原理
  10. Spring.NET教程(十五)——事务传播行为(基础篇)
  11. 2022美国大学生数学建模竞赛
  12. ibm java虚拟机_IBM java VM 最新版的java虚拟机下载及安装的一点说明
  13. Adobe Creative Cloud没有管理应用程序的权限
  14. 华为笔记本键盘说明图_笔记本电脑键盘各键名称与位置(最好有图)
  15. 天津大学仁爱学院计算机科学与技术学费,天津大学仁爱学院计算机科学与技术专业2016年在山西理科高考录取最低分数线...
  16. c语言代码大全复制,垃圾回收算法实现之 - 复制算法(完整可运行C语言代码)...
  17. monocle安装不成功 想尽各种办法
  18. WEB2.0下的金蛋 什么样的商业模式会成功?
  19. 企业员工生日提醒短信怎么发送
  20. 我的世界服务器配置推荐,搭建我的世界服务器教程

热门文章

  1. Arcgis Javascript那些事儿(七)--AMD详解
  2. 技术篇-符号制作-线符号制作
  3. tp5部署到nginx后所有分页404的解决办法
  4. Unity资源打包之Assetbundle
  5. 3D引擎多线程:资源异步加载
  6. C# 图片处理之:旋转图片任意角度
  7. Ros无法自动补全命令的解决
  8. 三、Nginx内置变量
  9. Hadoop的map阶段流程
  10. Flume之介绍 核心组件 可靠性 恢复性