标签:blog io ar for 数据 2014 on c log
题目信息如下:
题意分析:
快速方法就是将字母先重排几次,然后在与输入的重拍后的数据进行比较,快速简单。
代码如下:(此解法详解析参考《算法竞赛入门》)
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int n;
char a[2020][10],s[2020][10];
int cmp(const void *a,const void *b)
{
return *(char *)a-*(char *)b;
}
int cmp1(const void *a,const void *b)
{
char *c=(char *)a;
char *d=(char *)b;
return strcmp(c,d);
}
int main()
{
n=0;
for(;;)
{
scanf("%s",s[n]);
if(s[n][0]=='*')
{
break;
}
n++;
}
qsort(s,n,sizeof(s[0]),cmp1);
for(int i=0;i<n;i++)
{
strcpy(a[i],s[i]);
qsort(a[i],strlen(a[i]),sizeof(char),cmp);
}
char t[10];
while(~scanf("%s",t))
{
qsort(t,strlen(t),sizeof(char),cmp);
int found=0;
for(int i=0;i<n;i++)
{
if(strcmp(t,a[i])==0)
{
printf("%s ",s[i]);
found=1;
}
}
if(!found)
printf(":(");
printf("\n");
}
return 0;
}
标签:blog io ar for 数据 2014 on c log
原文地址:http://blog.csdn.net/ice_alone/article/details/39535315