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

hdu 1236,一直是runtime error,肿么回事啊该如何解决

2012-08-03 
hdu 1236,一直是runtime error,肿么回事啊?#includeiostream#includealgorithmusing namespace stdst

hdu 1236,一直是runtime error,肿么回事啊?
#include<iostream>
#include<algorithm>
using namespace std;
struct student{
  char name[30];
  int sum;
  }a[1010];
int ti[15];
int n,m,g;

bool cmp(student n1,student n2)
{ if(n1.sum!=n2.sum)
  return n1.sum>n2.sum;
  else
  return n1.name<n2.name;
}
int main()
{ int ch,s,c;
  while(scanf("%d",&n)&&n)
  {
  scanf("%d%d",&m,&g);
  for(int i=1;i<=m;i++)
  scanf("%d",&ti[i]);
  int result=0;
  for(int j=0;j<n;j++)
  { s=0;
  scanf("%s %d",&a[j].name,&ch);
  for(int k=0;k<ch;k++)
  { scanf("%d",&c);
  s=s+ti[c];
  }
  a[j].sum=s;
  if(s>=g)result++;
  }
  sort(a,a+n,cmp);
  printf("%d\n",result);
  for(int r=0;r<n;r++)
  {
  if(a[r].sum>=g)
  printf("%s %d\n",a[r].name,a[r].sum);
  }
  }
  system("pause");
  return 0;
}
   


[解决办法]
结帖率太低,怪不得没人理。
[解决办法]
runtime error,内存崩溃,检查你的数组越界没
[解决办法]
比较函数cmp有问题,改了下,测试成功,记得加<string>头文件

C/C++ code
bool cmp(student n1, student n2){     if(n1.sum != n2.sum)        return n1.sum > n2.sum;     else    {        string s1(n1.name);        string s2(n2.name);         return s1 < s2;    }}
[解决办法]
崩溃的时候在弹出的对话框按相应按钮进入调试,按Alt+7键查看Call Stack里面从上到下列出的对应从里层到外层的函数调用历史。双击某一行可将光标定位到此次调用的源代码或汇编指令处。

热点排行