小日本的巴嘎君


私信TA

用户名:uq_14514879941

访问量:312

签 名:

不想学秃头的程序猿不是好的厨子

等  级
排  名 961
经  验 3281
参赛次数 0
文章发表 3
年  龄 0
在职情况 学生
学  校 哔哩哔哩大学
专  业

  自我简介:

解题思路:

    前两个数相加即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 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区