复制代码
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 <cstdio> #include <cstring> #include <cstdlib> int len; char word[50][10]; char sorted[50][10]; int cmp_char(const void *_a, const void *_b){ char *a = (char*)_a; char *b = (char*)_b; return *a - *b; } int cmp_str(const void *_a, const void *_b){ char *a = (char*)_a; char *b = (char*)_b; return strcmp(a, b); } int main(){ memset(word, '', sizeof(word)); memset(sorted, '', sizeof(sorted)); len = 0; while (true){ scanf("%s", word[len]); if (word[len][0] == '*'){ break; } ++len; } qsort(word, len, sizeof(word[0]), cmp_str); for (int i = 0; i < len; ++i){ strcpy(sorted[i], word[i]); qsort(sorted[i], strlen(sorted[i]), sizeof(char), cmp_char); } char in[10]; memset(in, '', sizeof(in)); while (scanf("%s", in) == 1){ qsort(in, strlen(in), sizeof(char), cmp_char); bool found = false; for (int i = 0; i < len; ++i){ if (strcmp(in, sorted[i]) == 0){ printf("%s ", word[i]); found = true; } } if (!found){ printf(":("); } printf("n"); memset(in, '', sizeof(in)); } return 0; }
最后
以上就是激情星星最近收集整理的关于算法竞赛入门经典 5.3.2字母重排的全部内容,更多相关算法竞赛入门经典内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复