第31和36行qsort里面的的cmp_string和cmp_char是什么意思,开头写的这两个函数并没有给出确切的返回值啊
#include<stdio.h>#include<stdlib.h>#include<string.h>intn;charword[2000][10];charsort...
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int n;
char word[2000][10];
char sorted[2000][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);
}
int main()
{
n=0;
for(;;)
{
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[10];
while(scanf("%s",s)==1)
{
qsort(s,strlen(s),sizeof(char),cmp_char);
int found=0;
for(int i=0;i<n;i++)
if(strcmp(sorted[i],s)==0)
{
found=1;
printf("%s ",word[i]);
}
if(!found)
printf(":(");
printf("\n");
}
return 0;
}
//tarp given score refund only trap work earn course pepper part
//******
//resco nfudre aptr sett oresuc 展开
#include<stdlib.h>
#include<string.h>
int n;
char word[2000][10];
char sorted[2000][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);
}
int main()
{
n=0;
for(;;)
{
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[10];
while(scanf("%s",s)==1)
{
qsort(s,strlen(s),sizeof(char),cmp_char);
int found=0;
for(int i=0;i<n;i++)
if(strcmp(sorted[i],s)==0)
{
found=1;
printf("%s ",word[i]);
}
if(!found)
printf(":(");
printf("\n");
}
return 0;
}
//tarp given score refund only trap work earn course pepper part
//******
//resco nfudre aptr sett oresuc 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询