[TIOJ] 1679. 抽紙牌(poker)

題目連結:http://tioj.infor.org/problems/1679
把東東吃進來後排序並取到要取的位置即可,而且C++中有個東西叫做pair,他比大小自動就是先比第一項再比第二項
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,char> PCI;
#define N 52

PCI cards[N];

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n;cin>>n;
	for(int i=0;i<n;i++) cin>>cards[i].second>>cards[i].first;
	sort(cards,cards+n,[](PCI a, PCI b){return a>b;});
	int m;cin>>m;
	cout<<cards[m-1].second<<' '<<cards[m-1].first;
	return 0;
}

留言

這個網誌中的熱門文章

[TIOJ] 1902. 「殿仁.王,不認識,誰啊?」,然後他就死了……

[NPSC] 2009初賽 E. 檸檬汽水傳說

[AtCoder] [經典競程 90 題] 024 - Select +/- One(★2)