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
  • 相关阅读:
    java 缓存框架java caching system使用示例
    2020牛客寒假算法集训营2
    VJ train1 O统计问题 题解
    ACM#学习心得0
    2020牛客寒假集训营1
    高精度加减乘除
    VJ train1 I彼岸
    VC编译常见错误
    EVC开发MapXMobile 环境搭建
    用Evc+Pocket PC 2003 开发MapxMobie
  • 原文地址:https://www.cnblogs.com/gongxijun/p/3924831.html
Copyright © 2011-2022 走看看