PersonalCorpus 版 (精华区)
Your C++ program has solved Ok the problem 612 (DNA Sorting)
in 0.010 seconds with low memory spent.
void main()
{
int i,j,k,m,n,t,p;
char s[101][53];
int sum[100];
scanf("%d\n",&t);
while (t>0) {
t--;
scanf("%d%d\n",&m,&n);
for (i=0;i<n;i++) {
gets(s[i]); p=strlen(s[i]); sum[i]=0;
for (j=0;j<p-1;j++) for (k=j+1;k<p;k++)
if (s[i][j]>s[i][k]) sum[i]++;
}
for (i=0;i<n;i++) {
k=i;
for (j=i+1;j<n;j++) if (sum[k]>sum[j]) k=j;
printf("%s\n",s[k]);
if (k!=i) {
strcpy(s[k],s[i]);
sum[k]=sum[i];
}
}
gets(s[100]); if (t>0) printf("\n");
}
}
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:3.096毫秒