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 }
- 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 数组属性和方法