-
2008-05-26
初始化很关键!! - [艾西区姆]
版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://jaywee.blogbus.com/logs/21694758.html
PKU online judge 1007 --DNA Sorting
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
int n,m,i,j,k,a[100];
char dna[101][51],temp[51];
scanf("%d %d",&n,&m);
for(i=0;i<m;i++)
{
scanf("%s",dna[i]);
a[i] = 0;
}
for (i=0;i<m;i++){
for(j=0;j<n-1;j++){
for(k=j+1;k<n;k++){
if(dna[i][j]>dna[i][k])
a[i]++;
}
}
}
for(j=m-1;j>0;j--)
{
for(k=0;k<j;k++)
{
if(a[j]<a[k])
{
i=a[j];a[j]=a[k];a[k]=i;
strcpy(temp,dna[j]);
strcpy(dna[j],dna[k]);
strcpy(dna[k],temp);
}
}
}
for(i=0;i<m;i++)
printf("%s\n",dna[i]);
return 0;
}I do think my code is correct, but I forgot to initialize the the array a[100], when I submitted the problem, it turn out to be a Wrong Answer.
As the great coder Mr. zhao's word, never to forget to initialize a array.
随机文章:
吃饺子是否应该蘸醋?(BBS纠结回来有感) 2008-07-092008-05-31 2008-05-31奥运奥出政治,爱国爱成傻逼 2008-04-21精彩傻逼欣赏 2008-04-06firefox一个大,大,大彩蛋~!! 2008-04-06
收藏到:Del.icio.us






评论