hdu-----(1113)Word Amalgamation(字符串排序)
Word Amalgamation
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2586 Accepted Submission(s): 1246
Problem Description
In millions of newspapers across the United States there is a word game called Jumble. The object of this game is to solve a riddle, but in order to find the letters that appear in the answer it is necessary to unscramble four words. Your task is to write a program that can unscramble words.
Input
The input contains four parts: 1. a dictionary, which consists of at least one and at most 100 words, one per line; 2. a line containing XXXXXX, which signals the end of the dictionary; 3. one or more scrambled `words' that you must unscramble, each on a line by itself; and 4. another line containing XXXXXX, which signals the end of the file. All words, including both dictionary words and scrambled words, consist only of lowercase English letters and will be at least one and at most six characters long. (Note that the sentinel XXXXXX contains uppercase X's.) The dictionary is not necessarily in sorted order, but each word in the dictionary is unique.
Output
For each scrambled word in the input, output an alphabetical list of all dictionary words that can be formed by rearranging the letters in the scrambled word. Each word in this list must appear on a line by itself. If the list is empty (because no dictionary words can be formed), output the line ``NOT A VALID WORD" instead. In either case, output a line containing six asterisks to signal the end of the list.
Sample Input
tarp given score refund only trap work earn course pepper part XXXXXX resco nfudre aptr sett oresuc XXXXXX
Sample Output
score ****** refund ****** part tarp trap ****** NOT A VALID WORD ****** course ******
Source
代码:
1 #include<iostream>
2 #include<algorithm>
3 using namespace std;
4 struct node
5 {
6 char old[8];
7 char ne[8];
8 bool operator <(const node &a)const{
9 if(strcmp(old,a.old)<0) return 1;
10 return 0;
11 }
12 }str[105];
13 int main(){
14 int i=0;
15 //freopen("test.in","r",stdin);
16 while(scanf("%s",&str[i].old)&&str[i].old[0]!='X'){
17 strcpy(str[i].ne,str[i].old);
18 sort(str[i].ne,str[i].ne+strlen(str[i].ne));
19 i++;
20 }
21 int n=i;
22 sort(str,str+n);
23 char ss[8];
24 while(scanf("%s",ss)&&ss[0]!='X'){
25 sort(ss,ss+strlen(ss));
26 int cnt=0;
27 for(int i=0;i<n;i++){
28 if(strcmp(ss,str[i].ne)==0){
29 printf("%sn",str[i].old);
30 cnt++;
31 }
32 }
33 if(!cnt) puts("NOT A VALID WORD");
34 puts("******");
35 }
36 return 0;
37 }
- eclipse中关联文件设置方法
- Kubernetes服务网格(第8部分):Linkerd作为入口控制器
- 使用RestSharp 库消费Restful Service
- Python-面向对像及其他
- 基于MongoDB GridFS的图片存储
- css3 过渡和2d变换——回顾
- Microsoft 防跨站点脚本库AntiXSS Library v4.2.1
- Compilify——让你在浏览器中编译.NET代码
- Python进阶-面向对象
- WCF RESTful服务的Google Protocol Buffers超媒体类型
- 使用CoreOs,Docker和Nirmata部署微服务类型的应用
- .NET 4 上的REST 框架
- 结合游戏开发与人工智能研究,游戏大厂 Ubisoft 成立AI研发部门
- Quartz.NET的管理工具
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Ubuntu16.04源码安装Mininet
- Kotlin基础学习之Deprecated与Suppress注解使用
- Centos 7下利用crontab定时执行任务详解
- 树莓派无线上网时无屏幕下发现树莓派IP的方法
- Ubuntu18.04安装opencv 3.2.0的解决方法
- Android MVP BaseFragment 通用式封装的实现
- 腾讯云服务器Centos挂载数据盘的方法
- CentOS 8.0.1905 安装 ZABBIX4.4版本 (已验证)
- seaborn分类变量的汇总展示
- Linux查看PCIe版本及速率的方法
- android自定义滚轴选择器
- 虚拟机安装Linux rhel7.3操作系统(具体步骤)
- linux系统安装zookeeper 服务的方法
- 详解Linux中关于引号的那些事
- seaborn可视化数据框中的多个列元素