解题思路:
前两个数相加即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 人评分
A+B for Input-Output Practice (III) (C语言代码)浏览:577 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:812 |
C语言训练-素数问题 (C语言代码)浏览:998 |
C语言程序设计教程(第三版)课后习题6.11 (C语言代码)浏览:2081 |
C语言程序设计教程(第三版)课后习题8.4 (C语言代码)浏览:619 |
WU-格式化数据输出 (C语言代码)浏览:1755 |
C语言程序设计教程(第三版)课后习题8.5 (C语言代码)浏览:577 |
关于float,double变量的几点说明浏览:1810 |
蚂蚁感冒 (C语言代码)浏览:775 |
简单的a+b (C语言代码)浏览:541 |