| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 527 人关注过本帖
标题:为什么这个程序会runtime error?
只看楼主 加入收藏
墨清扬
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:1
帖 子:294
专家分:817
注 册:2011-10-4
结帖率:100%
收藏
已结贴  问题点数:6 回复次数:2 
为什么这个程序会runtime error?
#include "stdio.h"
#include "stdlib.h"
struct heigh
{
    char name[35];
    int a;
    int heigh;
    struct heigh *next;
    struct heigh *prev;
};
int comp(const void *a,const void *b)
{
    return (*(struct heigh **)a)->a-(*(struct heigh **)b)->a;
}
int main()
{
    struct heigh **queue,*temp;
    int total,i,j;
    scanf("%d",&total);
    queue=(struct heigh**)calloc(total,sizeof(struct heigh*));
    for(i=0;i<total;i++)
        queue[i]=(struct heigh*)malloc(sizeof(struct heigh));
    for(i=0;i<total;i++)
        scanf("%s%d",queue[i]->name,&queue[i]->a);

    qsort(queue,total,sizeof(struct heigh *),comp);
    for(i=0;i<total;i++)
        if(queue[i]->a>i)
            break;
    if(i<total)
        printf("-1");
    else
    {
        queue[0]->heigh=3001;
        queue[0]->next=queue[0]->prev=NULL;
        for(i=1;i<total;i++)
        {
            temp=queue[i-1];
            j=queue[i]->a-temp->a;
            for(;j>0;j--,temp=temp->prev);//寻找合适位置
            queue[i]->heigh=temp->heigh;
            queue[i]->next=temp->next;//关系重组
            if(temp->next!=NULL)
                temp->next->prev=queue[i];
            temp->next=queue[i];
            queue[i]->prev=temp;
            for(;temp!=NULL;temp=temp->prev)//前面减小
                temp->heigh--;
        }
        for(i=0;i<total;i++)
            printf("%s %d\n",queue[i]->name,queue[i]->heigh);
    }
    return 0;
}
输入是total行,每行一个名字一个数值,我把出错的那一个输入手动测试了一下,发现没有问题,但是OJ就告诉我runtime error……有时也会遇上这种事,本机正常但是ojruntime error,查都查不出来,有没有经验可以让我参考一下?
搜索更多相关主题的帖子: void next include return 
2012-01-11 15:52
laoyang103
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:内蒙古包头
等 级:贵宾
威 望:19
帖 子:3082
专家分:11056
注 册:2010-5-22
收藏
得分:4 
可以的话发下网址  我们也没有你OJ的测试数据

                                         
===========深入<----------------->浅出============
2012-01-11 16:00
墨清扬
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:1
帖 子:294
专家分:817
注 册:2011-10-4
收藏
得分:0 
9
kyywkcoaw 8
owxo 1
zvjjqlre 0
dlwnpxp 2
kytj 4
ba 7
dppua 6
bf 3
nuis 5
这个是数据

酱油实习生
2012-01-11 17:18
快速回复:为什么这个程序会runtime error?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014330 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved