解题思路:
前两个数相加即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++代码)浏览:862 |
C语言程序设计教程(第三版)课后习题6.10 (C语言代码)浏览:749 |
C语言程序设计教程(第三版)课后习题7.3 (C语言代码)浏览:1195 |
C二级辅导-阶乘数列 (C语言代码)浏览:688 |
C语言训练-大、小写问题 (C语言代码)浏览:724 |
WU-蓝桥杯算法提高VIP-Quadratic Equation (C++代码)浏览:1745 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:853 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:518 |
回文数(一) (C语言代码)浏览:1117 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:420 |