-
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.
随机文章:
windows下netbeans 6.0 C/C++的超快捷配置方法 2008-04-08熬夜写剧本 2008-04-03我和我的姑娘们的谈话(一) 2008-04-01八十年代人道主义 2008-03-08windows下netbeans 6.0 C/C++的配置 2008-03-05
收藏到:Del.icio.us








评论