这道还是不错的一道题目,主要是涉及的知识点就是排序模版的运用,在一个就是用内存来解决多重运用的问题;
诶呀呀 还是多做点题目好一点,主要是自己可以多学习思想,如果只是停留在看上面,你是学不会的,
其实聪明的人,大有所在,而我真不算聪明的,所以自己只能使用记呀,背呀,还有就是写来弥补了!
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
using namespace std;
char word[2000][10];
char sorted[2000][10];
int cmp_string(const void *_a, const void *_b)
{
char *a = (char *)_a;
char *b = (char *)_b;
return strcmp(a, b);
}
bool cmp_char(char a, char b)
{
return a < b;
}
int main()
{
char s[10];
char t[10];
int cnt = 0;
while (scanf("%s", word[cnt]) != EOF)
{
strcpy(sorted[cnt], word[cnt]);
if (word[cnt][0] == '*')
{
break;
}
cnt++;
}
qsort(word, cnt, sizeof (word[0]), cmp_string);
qsort(sorted, cnt, sizeof (sorted[0]), cmp_string);
// cout << "word = " << word[0] << endl;
for (int i = 0; i < cnt; i++)
{
sort(sorted[i], sorted[i] + strlen(sorted[i]), cmp_char);
}
while (scanf("%s", s) != EOF)
{
// cout << "s =" << s;
int n = strlen(s);
sort(s, s + n, cmp_char);
// cout << "changed s = " << s << endl;
for (int i = 0; i < cnt; i++)
{
if (strcmp(sorted[i], s) == 0)
{
if (i == 0)
{
cout << word[i];
}
else
{
cout << " " << word[i];
}
}
}
cout << endl;
}
system("pause");
return 0;
}