首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

poj 1007 wa了,求解答,该如何解决

2013-01-07 
poj 1007 wa了,,求解答#includestdio.h#includestring.h#includestdlib.hint sort(char *s,int temp

poj 1007 wa了,,求解答
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int sort(char *s,int temp)
{
int num=0;
int i=0,j=0;
int k=0;
    int swap=0;
char str[51];

memset(str,NULL,51);
for(k=0;k<temp;k++)
{
str[k] = s[k];
}


for(i=temp-1;i>0;i--)
{
        for(j=0;j<i;j++)
        {
            if(str[j] > str[j+1])
            {
                swap = str[j];
                str[j] = str[j+1];
                str[j+1] = swap;
                num++;
            }
        }
}

return num;
}

int min(int *num,int temp)
{
    int i=0,j;
int re=0;
    j=num[0];

    for(i=0;i<temp;i++)
    {
       if(num[i] < j)
   {
       j=num[i];
re=i;
   }
    }
    return re;
}

int main()
{
char str[51][100];
int row=0;
int col=0;
int temp1=0,temp2=0,temp3=0;
int num[100];
int sortnum[100];
    int c=0;

memset(sortnum,NULL,100);
memset(str,NULL,5100);
memset(num,NULL,100);

scanf("%d %d",&col,&row);

for(temp1 = 0;temp1 < row; temp1++)
{
scanf("%s",&str[temp1]);
num[temp1] = sort(str[temp1],col);
}

for(temp1 = 0;temp1 < row;temp1++)
{
c = min(num,row);
        num[c] = 5000;
printf("%s\n",str[c]);
}

return 0;
}


[解决办法]
char str[51][100];
->
char str[100][51];

热点排行