1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int n;
char word[ 1000][10 ],sorted[ 1000][10 ];
//字符比较函数
int cmp_char(const void * _a, const void *_b)
{
    char* a=(char*)_a ;
    char* b=(char*)_b ;
    return *a-* b;
}
int cmp_string(const void * _a,const void * _b)
{
    char* a=(char *) _a;
    char* b=(char *) _b;
    return strcmp (a, b);
}
 
void main()
{
    int i;
    char s[10 ];
    n=0 ;
    for(;;)
    {
        scanf ("%s",word[n ]);
         if(word [n][ 0]=='*' )break;
        n ++;
    }
    qsort(word ,n, sizeof(word [0]), cmp_string);// 给所有单词排序
    for(i=0 ;i< n;i++)
    {
        strcpy (sorted[ i],word[i ]);
        qsort (sorted[ i],strlen(sorted [i]), sizeof(char ),cmp_char);
    }
 
    while(scanf("%s" ,s)== 1)// 持续督导文件结束
    {
         int found =0;
        qsort (s, strlen(s ),sizeof(char),cmp_char );
         for(  i =0; i<n;i ++)
             if(strcmp (sorted[ i],s)==0 )
             {
                found =1;
                printf ("%s ",word[i ]);
             }
             if(!found )printf":(");
            printf ("\n");
    }
}

[code]字母重排的更多相关文章

  1. Algorithm --> 字母重排

    字母重排 输入一个字典(用***结尾),然后再输入若干单词.没输入一个单词w,都需要在字典中找出所有可以用w的字幕重排后得到的单词,并按照字典序从小到大的顺序在一行中输出,如果不存在,输出“:(”.单 ...

  2. Problem D Ananagrams(map的使用)

    题目链接:Problem D 题意:输入一些单词,找出所有满足如下条件的单词:该单词不能通过字母重排,得到输入文本中的另一个单词.在判断是否满足条件时,字母不区分大小写. 但是输出时应保留原始大小写, ...

  3. Codeforces 补题记录

    首先总结一下前段时间遇到过的一些有意思的题. Round #474 (Div. 1 + Div. 2, combined)   Problem G 其实关键就是n这个数在排列中的位置. 这样对于一个排 ...

  4. Codeforces Round #524 (Div. 2) codeforces 1080A~1080F

    目录 codeforces1080A codeforces 1080B codeforces 1080C codeforces 1080D codeforces 1080E codeforces 10 ...

  5. 算法入门笔记------------Day4

    1.WERTYU 输入一个错位后敲出的字符串,输出打字员本来想打出的字 #include<stdio.h> char *s="`1234567890-=QWERTYUIOP[]\ ...

  6. UVA 156 Ananagrams ---map

    题目链接 题意:输入一些单词,找出所有满足如下条件的单词:该单词不能通过字母重排,得到输入文本中的另外一个单词.在判断是否满足条件时,字母不分大小写,但在输出时应保留输入中的大小写,按字典序进行排列( ...

  7. hdu 1113 Word Amalgamation 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1113 题意:输入一个字典,然后再输入若干单词(每行中,1 <= 单词数 <= 100,并且 ...

  8. UVa 156 Ananagrams

    题意:给出一些单词,在这些单词里面找出不能通过字母重排得到的单词(判断的时候不用管大小写),然后按照字典序输出. 学习的紫书的map= = 将每一个单词标准化 先都转化为小写,再排序(即满足了题目中说 ...

  9. 排列组合函数next_permutation()

    next_permution(),按照字典序进行排列组合, 括号里的参数为类似sort里面的参数,用法相同 #include <bits/stdc++.h> using namespace ...

随机推荐

  1. FreeMarker 小结

    一.Sequence 的内置函数1.sequence?first 返回sequence 的第一个值.2.sequence?last 返回sequence 的最后一个值.3.sequence?rever ...

  2. sql随机

    想从MySQL数据库中随机取一条或者N条记录时,最好把RAND()生成随机数放在JOIN子查询中以提高效率. SELECT id FROM table ORDER BY RAND() LIMIT n; ...

  3. socket编程,简单多线程服务端测试程序

    socket编程,简单多线程服务端测试程序 前些天重温了MSDN关于socket编程的WSAStartup.WSACleanup.socket.closesocket.bind.listen.acce ...

  4. Ubuntu+Django+mod_wsgi+Apache配置过程

    Ubuntu15.10 Apache2.4( sudo apt-get install apache2 ) Python3.4( sudo apt-get install apache2 ),  [系 ...

  5. android代码格式化方法小结

    转载:http://blog.csdn.net/androidzhaoxiaogang/article/details/7692526 Download the android-formatting. ...

  6. linux脚本Shell之awk详解(二)

    三.printf的使用   print format 生成报表 %d        十进制有符号整数 %u        十进制无符号整数 %f        浮点数 %s        字符串 %c ...

  7. cp 覆盖 \cp a test\a

    使用cp命令覆盖文件总是提示要输入yes或no,一个两个就算了,大量的文件复制就不行了,即使加上-f参数也无法强行覆盖.苦思冥想不得解,终于在查阅了众多资料后让我找到了解决方法,这里写出来,让有同样困 ...

  8. hdu_4046_Panda(树状数组)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4046 题意:一大堆篇幅介绍,跳过直奔主题,让你寻找给定区间的“wbw”的个数. 题解:直接上树状数组, ...

  9. malloc without free, what happens?

    It's per-process. Once your process exits, the allocated memory is returned to the OS for use by oth ...

  10. repeat a string in java

    if I want to repeat "hello" four times as a new string-> "hellohellohellohello&quo ...