acm HDU 1084 报错为Runtime Error(ACCESS_VIOLATION)#include #include #include #include #define N 100+10using namespace std;struct student{int slove;string time;int idx;int score;};struct student a[N];bool cmp1(student a,student b){if (a.slove = b.s
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/28 12:14:27
acm HDU 1084 报错为Runtime Error(ACCESS_VIOLATION)#include #include #include #include #define N 100+10using namespace std;struct student{int slove;string time;int idx;int score;};struct student a[N];bool cmp1(student a,student b){if (a.slove = b.s
acm HDU 1084 报错为Runtime Error(ACCESS_VIOLATION)
#include
#include
#include
#include
#define N 100+10
using namespace std;
struct student
{
int slove;
string time;
int idx;
int score;
};
struct student a[N];
bool cmp1(student a,student b)
{
if (a.slove = b.slove)
return a.slove > b.slove;
else
a.time < b.time;
}
bool cmp2(student a,student b)
{
return a.idx < b.idx;
}
int main()
{
int n,i,slovenum[6];
int p1 = 0,p2 = 0,p3 = 0,p4 = 0;
while (cin>> n&&n = -1)
{
memset(slovenum,0,sizeof(slovenum));
for (i = 0;i < n;i++)
{
cin >> a[i].slove >> a[i].time;
a[i].idx = i + 1;
slovenum[a[i].slove]++;
}
sort(a,a + n,cmp1);
for (i = 0;i
acm HDU 1084 报错为Runtime Error(ACCESS_VIOLATION)#include #include #include #include #define N 100+10using namespace std;struct student{int slove;string time;int idx;int score;};struct student a[N];bool cmp1(student a,student b){if (a.slove = b.s
有几个隐蔽的小错误:
一是,没有写return
bool cmp1(student a,student b)
{
if (a.slove != b.slove)
return a.slove > b.slove;
else
a.time < b.time; <- 这里
}
二是,题目中只说了负数,没说是-1结束
while (cin>> n&&n != -1) 改为 n >= 0
三是,pX没有初始化:
memset(slovenum, 0, sizeof(slovenum));
这里应把p1,p2,p3,p4也初始化为0.