zoukankan      html  css  js  c++  java
  • 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("%s
    ",str[i].old);
    30              cnt++;
    31            }
    32        }
    33        if(!cnt) puts("NOT A VALID WORD");
    34        puts("******");
    35     }
    36  return 0;
    37 }
    View Code
  • 相关阅读:
    BZOJ3498PA2009 Cakes——三元环
    黑科技之三元环讲解
    BZOJ4317Atm的树&BZOJ2051A Problem For Fun&BZOJ2117[2010国家集训队]Crash的旅游计划——二分答案+动态点分治(点分树套线段树/点分树+vector)
    BZOJ2463[中山市选2009]谁能赢呢?——博弈论
    BZOJ2275[Coci2010]HRPA——斐波那契博弈
    BZOJ2281[Sdoi2011]黑白棋&BZOJ4550小奇的博弈——DP+nimk游戏
    BZOJ3435[Wc2014]紫荆花之恋——动态点分治(替罪羊式点分树套替罪羊树)
    Trie树学习总结
    kmp学习小结
    Hash学习小结
  • 原文地址:https://www.cnblogs.com/gongxijun/p/3924831.html
Copyright © 2011-2022 走看看