There have a sample I/O I have tried.
Code: Select all
Sample Input
8 6
5 2 20 1 30 10
23 15 7 9 11 3
40 50 34 24 14 4
9 10 11 12 13 14
31 4 18 8 27 17
44 32 13 19 41 19
1 2 3 4 5 6
80 37 47 18 21 9
Sample Output
4
7 2 5 6
4
7 2 5 8
Is it right and can be accepted?
Here is my code:
Code: Select all
#include <stdio.h>
#include <stdlib.h>
main()
{ int i,j,t,m,a[32][12]={0},k,n,tmp,s[32]={0},b[32]={0},e[32]={0},p=0;
while(scanf("%d %d",&k,&n)==2)
{ for(i=1;i<=k;i++)
{ b[i]=i;
for(j=1;j<=n;j++)
{ scanf("%d",&a[i][j]);
} }
for(t=1;t<=k;t++)
{ for(i=n;i>1;i--)
{ for(j=1;j<i;j++)
{ if(a[t][j]>a[t][j+1])
{ tmp=a[t][j+1];
a[t][j+1]=a[t][j];
a[t][j]=tmp;
} } }
s[t]=a[t][1];
}
for(i=k;i>1;i--)
{ for(j=1;j<i;j++)
{ if(s[j]>=s[j+1])
{ tmp=s[j+1];
s[j+1]=s[j];
s[j]=tmp;
tmp=b[j+1];
b[j+1]=b[j];
b[j]=tmp;
} } }
for(j=1;j<k;j++)
{ if(s[j]==s[j+1])
{ t=1;
while(a[b[j]][t]==a[b[j+1]][t])
t++;
if(a[b[j]][t]>a[b[j+1]][t])
{ tmp=s[j+1];
s[j+1]=s[j];
s[j]=tmp;
tmp=b[j+1];
b[j+1]=b[j];
b[j]=tmp;
} } }
t=1;
e[t]=b[1];
m=1;
for(i=1;i<k;i++)
{ for(j=1;j<=n;j++)
{ if(a[b[m]][j]>=a[b[i+1]][j])
{ p=1;
break;
}
}
if(p==0)
{ t++;
e[t]=b[i+1];
m=i+1;
}
p=0;
}
printf("%d\n",t);
for(i=1;i<=t;i++)
printf("%d ",e[i]);
printf("\n");
} /* while */
} /* main */