输入:
tarp given score refund only trap work earn course pepper part *******
resco nfudre aptr sett oresuc
输出:
score
refund
part tarp trap
:(
course
//
// main.cpp
// 字母重排
//
// Created by 张嘉韬 on 16/1/29.
// Copyright © 2016年 张嘉韬. All rights reserved.
//
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
char word[10000][20],sorted[100000][20];
int cmp_string(const void*_a,const void *_b)
{
char *a=(char *)_a;
char *b=(char *)_b;
return strcmp(a,b);
}
int cmp_char (const void *a,const void *b)
{
return *(char *)a-*(char*)b;
}
int main(int argc, const char * argv[]) {
//freopen("/Users/zhangjiatao/Desktop/input.txt","r",stdin);
int n;
n=0;
while(1)
{
scanf("%s",word[n]);
if(word[n][0]=='*') break;
n++;
}
qsort(word,n,sizeof(word[0]),cmp_string);
for(int i=0;i<n;i++)
{
strcpy(sorted[i],word[i]);
qsort(sorted[i],strlen(sorted[i]),sizeof(char),cmp_char);
}
char s[20];
while(scanf("%s",s)==1)
{
int counter=0;
qsort(s,strlen(s),sizeof(char),cmp_char);
for(int i=0;i<n;i++)
{
if(strcmp(s,sorted[i])==0)
{
cout<<word[i]<<" ";
counter++;
}
}
if(counter!=0) cout<<endl;
if(counter==0) cout<<":("<<endl;
}
return 0;
}