王大越呦
2019-04-20 09:54牛客网PAT德才论 sort函数触发中断
求助大佬。编程小白在做牛客网PAT德才论问题时调用sort函数时触发了中断。当输入数据样本是4个时程序可以正常运行,但是数据样本多了就会在sort函数那里触发中断,实在是找不到代码哪里存在问题,请大佬帮忙看一下。
#include"stdafx.h"
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct dcl
{
long x;
int y;
int z;
int sum = y + z;
};
bool cmp(const dcl&a, const dcl&b)
{
if (a.sum > b.sum)
{
return a.sum > b.sum;
}
else if (a.sum == b.sum)
{
return a.y > b.y;
}
else if (a.y == b.y)
{
return a.x < b.x;
}
else
{
return false;
}
}
int main()
{
int n , l , h,count=0;
cin >> n>>l>>h;
vector<dcl> a;
for (int i = 0; i < n; i++)
{
dcl b;
cin >> b.x >> b.y >> b.z;
if (b.y >= l&&b.z >= l)
{
a.push_back(b);
count++;
}
}
vector<dcl>one;
vector<dcl>two;
vector<dcl>three;
vector<dcl>four;
for (int i = 0; i < count; i++)
{
if (a[i].y >= h&&a[i].z >= h)
{
one.push_back(a[i]);
}
else if (a[i].y >= h&&a[i].z < h)
{
two.push_back(a[i]);
}
else if (a[i].y < h&&a[i].z < h&&a[i].y >= a[i].z)
{
three.push_back(a[i]);
}
else
{
four.push_back(a[i]);
}
}
sort(one.begin(), one.end(), cmp);
sort(two.begin(), two.end(), cmp);
sort(three.begin(), three.end(), cmp);
sort(four.begin(), four.end(), cmp);
cout << count << endl;
for (int i = 0; i < one.size(); i++)
{
cout << one[i].x << " " << one[i].y << " " << one[i].z << endl;
}
for (int i = 0; i < two.size(); i++)
{
cout << two[i].x << " " << two[i].y << " " << two[i].z << endl;
}
for (int i = 0; i < three.size(); i++)
{
cout << three[i].x << " " << three[i].y << " " << three[i].z << endl;
}
for (int i = 0; i < four.size(); i++)
{
cout << four[i].x << " " << four[i].y << " " << four[i].z << endl;
}
system("pause");
return 0;
}
- 点赞
- 回答
- 收藏
- 复制链接分享
0条回答
为你推荐
- pat乙级 1031查验身份证
- c语言
- 1个回答
- pat乙级 1046 划拳答案部分正确,求各位前辈指点!
- c语言
- 1个回答
- PAT乙级1019数字黑洞2,3,4测试点无法通过
- c++
- 2个回答
- 从javascript代码中调用Golang函数
- javascript
- 1个回答
- PAT乙级1059 C语言竞赛 测试点2通过不了,求助呀
- c
- 2个回答
换一换