貌似是下标溢出了。。。不理解。。。
#include <stdio.h>#include <stdlib.h>
#include <string.h>
int main()
{
char date[11000][20],temp[20];
int i=0,p,n,j;
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
while (scanf("%s",date[n])!=-1)
{
n++;
}
for (j=0;j<n-1;j++) //ri
{
for (i=0;i<n-j-1;i++)
{
for (p=1;p>=0;p--)
{
if (date[i][p]>date[i+1][p])
{
strcpy(temp,date[i]);
strcpy(date[i],date[i+1]);
strcpy(date[i+1],temp);
}
}
}
}
for (j=0;j<n-1;j++) //y
{
for (i=0;i<n-j-1;i++)
{
for (p=4;p>=3;p--)
{
if (date[i][p]>date[i+1][p])
{
strcpy(temp,date[i]);
strcpy(date[i],date[i+1]);
strcpy(date[i+1],temp);
}
}
}
}
for (j=0;j<n-1;j++) //n
{
for (i=0;i<n-j-1;i++)
{
for (p=9;p>=6;p--)
{
if (date[i][p]>date[i+1][p])
{
strcpy(temp,date[i]);
strcpy(date[i],date[i+1]);
strcpy(date[i+1],temp);
}
}
}
}
for (i=0;i<n;i++)
{
printf("%s\n",date[i]);
}
return 0;
}
01/01/2012
02/01/2010
02/01/2012
10/01/2010
10/01/2012
01/01/2010
02/10/2000
02/10/2012
01/10/2010
10/10/2010
10/10/2000
02/10/2012
01/10/2010
01/10/2012
02/01/2000
30/01/1999
上面是一组数据