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
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.
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.
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.
given
score
refund
only
trap
work
earn
course
pepper
part
XXXXXX
resco
nfudre
aptr
sett
oresuc
XXXXXX
******
refund
******
part
tarp
trap
******
NOT A VALID WORD
******
course
******
#include<iostream>
#include<algorithm>
using namespace std;
struct node
{
char old[];
char ne[];
bool operator <(const node &a)const{
if(strcmp(old,a.old)<) return ;
return ;
}
}str[];
int main(){
int i=;
//freopen("test.in","r",stdin);
while(scanf("%s",&str[i].old)&&str[i].old[]!='X'){
strcpy(str[i].ne,str[i].old);
sort(str[i].ne,str[i].ne+strlen(str[i].ne));
i++;
}
int n=i;
sort(str,str+n);
char ss[];
while(scanf("%s",ss)&&ss[]!='X'){
sort(ss,ss+strlen(ss));
int cnt=;
for(int i=;i<n;i++){
if(strcmp(ss,str[i].ne)==){
printf("%s\n",str[i].old);
cnt++;
}
}
if(!cnt) puts("NOT A VALID WORD");
puts("******");
}
return ;
}
hdu-----(1113)Word Amalgamation(字符串排序)的更多相关文章
- hdu - 1113 Word Amalgamation (stl)
http://acm.hdu.edu.cn/showproblem.php?pid=1113 给定一个字典,然后每次输入一个字符串问字典中是否有单词与给定的字符串的所有字母一样(顺序可以打乱),按字典 ...
- poj1318 Word Amalgamation 字符串排序(qsort)
Word Amalgamation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9794 Accepted: 4701 ...
- hdu 1113 Word Amalgamation 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1113 题意:输入一个字典,然后再输入若干单词(每行中,1 <= 单词数 <= 100,并且 ...
- HDU 1113 Word Amalgamation (map 容器 + string容器)
http://acm.hdu.edu.cn/showproblem.php?pid=1113 Problem Description In millions of newspapers across ...
- hdu 1113 Word Amalgamation
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1113 字符串简单题: stl水过 如下: #include<algorithm> #inc ...
- ZOJ1181 Word Amalgamation 字符串 排序查找
传送门:ZOJ1181 思路:自身排序来判断两个字符串拥有相同的字符. #include<cstdio> #include<cstdlib> #include<io ...
- HDOJ/HDU 1113 Word Amalgamation(字典顺序~Map)
Problem Description In millions of newspapers across the United States there is a word game called J ...
- HDOJ.1113 Word Amalgamation(map)
Word Amalgamation 点我挑战题目 点我一起学习STL-MAP 题意分析 给出字典.之后给出一系列======乱序======单词,要求你查字典,如过这个乱序单词对用有多个有序单词可以输 ...
- Word Amalgamation(枚举 + 排序)
Word Amalgamation Time Limit: 1 Sec Memory Limit: 64 MB Submit: 373 Solved: 247 Description In mil ...
随机推荐
- Spring注解【非单例】
花了至少一整天的时间解决了这个问题,必须记录这个纠结的过程,问题不可怕,思路很绕弯. 为了能说清楚自己的问题,我都用例子来模拟. 我有一个类MyThread是这样的: @Service public ...
- [51NOD1393]0和1相等串(前缀和,map)
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1393 题意:中文题面. 把0看成是-1,并且存一遍前缀和.这样 ...
- Maven开发基础总结(Maven自启动,Maven打war包,Maven热部署)
学习内容: 1.不依赖外部Tomcat,自己启动方式部署 2.Maven打war包,远程部署到centOS 3.Maven热部署(不关闭Tomcat部署应用) 做maven开发前提: 1.编码UT ...
- [Java解惑]类
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- 线程入门之优先级priority
package com.thread; /** * 优先级: * Thread.MAX_PRIORITY:最大优先级 10 * Thread.MIN_PRIORITY:最小优先级 1 * Thread ...
- C# 创建一个日志文件
private static string m_fileName = "C:\\ErrorMsg.txt"; public static void CreateErrorLog(s ...
- Doragon Kuesuto 1.15
#include<stdio.h> #include<stdlib.h> #include<time.h> int main() { ; ; ; int actio ...
- [转载] Tmux 速成教程:技巧和调整
原文: http://blog.jobbole.com/87584/ 决定从 screen 转向 tmux 了, 非常喜欢 tmux 的窗格功能. 简介 有些开发者经常要使用终端控制台工作,导致最终打 ...
- poj2420A Star not a Tree?(模拟退火)
链接 求某一点到其它点距离和最小,求这个和,这个点 为费马点. 做法:模拟退火 #include <iostream> #include<cstdio> #include< ...
- Java字符串处理函数
substring() 它有两种形式,第一种是:String substring(int startIndex)第二种是:String substring(int startIndex,int end ...