解题思路:
前两个数相加即vector元素个数,pair将两个数据组合成一个元素,v.push_back后 sort
注意:
make_pair()是函数 别写成<>
参考代码:
/************************************************************************* > File Name: 1052.cpp > Author: Jincheng Xie > Mail: chengdiy@foxmail.com > Created Time: 三 3/ 8 23:09:50 2023 ************************************************************************/ #include <iostream> #include <vector> #include <algorithm> using namespace std; int main () { int n,b,c; vector<pair<int,int >> v; cin >> n >> b; n += b; for(int i = 0 ; i < n; i++) { cin >> b >> c; v.push_back(make_pair(b,c)); } auto cmp = [](pair<int,int>& p1,pair<int,int>& p2){ return p1.first<p2.first; }; sort(v.begin(),v.end(),cmp); for(int i = 0; i < n; i++) { cout << v[i].first << " " << v[i].second<< endl; } return 0; }
0.0分
0 人评分
九宫重排 (C++代码)浏览:2160 |
C语言程序设计教程(第三版)课后习题10.5 (C语言代码)浏览:1450 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:904 |
数组输出 (C语言代码)--此题的题目描述有问题浏览:1817 |
C语言程序设计教程(第三版)课后习题6.2 (C语言代码)浏览:1420 |
WU-格式化数据输出 (C语言代码)浏览:1755 |
C语言程序设计教程(第三版)课后习题6.8 (C++代码)浏览:592 |
The 3n + 1 problem (C语言代码)浏览:554 |
C语言程序设计教程(第三版)课后习题9.8 (C语言代码)浏览:677 |
2004年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:600 |