这个代码就是AC不了~不知为什么~
程序代码:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct Node
{
int month;
int day;
int flag;
char name[21];
}Node;
Node stu[180]={0};
int comp(void const *stu_a,void const *stu_b)
{
Node *a=(Node *)stu_a;
Node *b=(Node *)stu_b;
if (a->month<b->month)
return -1;
if (a->month>b->month)
return 1;
if (a->day<b->day)
return -1;
if (a->day>b->day)
return 1;
if (strlen(a->name)<strlen(b->name))
return -1;
if (strlen(a->name)>strlen(b->name))
return 1;
return strcmp(a->name,b->name);
}
void print(Node *stu)
{
static int month=0;
static int day=0;
if (month==0)
printf ("%d %d",stu->month,stu->day);
else if (month!=stu->month&&day!=stu->day)
printf ("\n%d %d",stu->month,stu->day);
month=stu->month;
day=stu->day;
printf(" %s",stu->name);
}
int main()
{
int n=0;
int i=0;
int flag=0;
memset(stu,0,sizeof(stu));
scanf("%d",&n);
for (i=0;i<n;i++)
{
scanf("%s",stu[i].name);
scanf("%d",&stu[i].month);
scanf("%d",&stu[i].day);
}
qsort(stu,n,sizeof(stu[0]),comp);
for (i=0;i<n;i++)
{
if (i&&stu[i-1].month==stu[i].month&&stu[i-1].day==stu[i].day)
{
stu[i-1].flag=1;
stu[i].flag=1;
flag=1;
}
}
for (i=0;i<n&&flag;i++)
if (stu[i].flag)
print(&stu[i]);
if (flag==0)
printf("None");
printf("\n");
return 0;
}
看看是哪一种测试数据过不了~~~~~~
[此贴子已经被作者于2017-2-7 13:11编辑过]