zoukankan      html  css  js  c++  java
  • HDU 1113 Word Amalgamation

    Word Amalgamation
    Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%lld & %llu
     

    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
    ******


    数据比较水 因为懒只做了前两个字母的排序 竟然过了......
    strcmp大法好 另外一个点就是用sort对字符串进行排序

    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>
    using namespace std;
    
    struct node
    {
        char c[10];
    }a[105],b[105],re[105];
    
    int cmp(node a,node b){
        if(a.c[0]==b.c[0])
            return a.c[1]<b.c[1];
        else
            return a.c[0]<b.c[0];
    }
    int main()
    {
        //freopen("input.txt","r",stdin);
        int num=0;
        while(1)
        {
            num++;
            scanf("%s",a[num].c);
            int len=strlen(a[num].c);
            for(int i=0;i<len;i++)
            {
                re[num].c[i]=a[num].c[i];
            }
            if(strcmp(a[num].c,"XXXXXX")==0)
                break;
        }
            sort(a+1,a+num,cmp);
            sort(re+1,re+num,cmp);
    
        for(int i=1;i<=num-1;i++)
        {
            int len=strlen(a[i].c);
            sort(a[i].c,a[i].c+len);
        }
        int num2=0;
         while(1)
        {
            num2++;
            scanf("%s",b[num2].c);
            int len2=strlen(b[num2].c);
            sort(b[num2].c,b[num2].c+len2);
            if(strcmp(b[num2].c,"XXXXXX")==0)
                break;
        }
    
    
            for(int j=1;j<=num2-1;j++)
            {
                int flag=0;
                for(int i=1;i<=num-1;i++)
                {
                    if(strcmp(a[i].c,"XXXXXX")==0)
                        continue;
                    if(strcmp(a[i].c,b[j].c)==0)
                    {
                        printf("%s
    ",re[i].c);
                        flag=1;
                    }
                }
                if(flag)
                    printf("******
    ");
                else
                    {
                        printf("NOT A VALID WORD
    ");
                        printf("******
    ");
                    }
            }
    
    
    }
    

      



  • 相关阅读:
    mysql库操作
    mysql初识
    numpy科学计算库
    pycharm下安装numpy
    Kettle汇总时参数
    PL/SQL连接查询数据报错时Dynamic Performance Tables not accessible
    HBase Shell输入命令无法删除问题解决技巧
    linux系统利用yum安装其他软件或服务
    Web安全测试
    用户名和密码测试
  • 原文地址:https://www.cnblogs.com/Hyouka/p/5705959.html
Copyright © 2011-2022 走看看