题库首页 › 信息学奥赛 › 题目 15522

完善程序(2) 6-10题 组合题 (计数排序)计数排序是一个广泛使用的排序方法。下面的程序使用双关键字 计数排序,将n对10000以内的整数,从小到大排序。 例如有三对整数(3, 4) (3, 4)、(2, 4) (2, 4)、(3, 3) (3, 3),那么排序之后应该是 (2, 4) (2, 4)、(3, 3) (3, 3)、(3, 4) (3, 4)。 输入第一行为nn接下来nn行,第ii行有两个数a[i]a[i]和b[i]b[i]分别表 示第ii对整数的第一关键字和第二关键字。 从小到大排序后输出。 数据范围 提示:应先对第二关键字排序,再对第一关键字排序。数组。ord[ ]存储第二关键 字排序的结果,数组res[ ]存储双关键字排序的结果。 试补全程序。 #include #include using namespace std; const int maxn = 10000000; const int maxs = 10000; int n; unsigned a[maxn], b[maxn],res[maxn], ord[maxn]; unsigned cnt[maxs + 1]; int main() { scanf("%d", &n); for (int i = 0; i = 0; --i) ④ // 记录最终排序结果 for (int i = 0; i < n; i++) printf("%d %d", ⑤); return 0; }

完善程序(2) 6-10题 组合题 (计数排序)计数排序是一 题目配图

试卷来源:2019 CSP-J入门级(第一轮)C++真题

本卷相关题目

在线做题 同科目题库