複合型別
pair(first,second)
#include<bits/stdc++.h>
using namespace std;
int main() {
pair<int, string> p(1, "apple");
cout << p.first << p.second << endl;
return 0;
}
結構體
/*
* m931. 1. 遊戲選角
* C++
* AC (2ms, 324KB)
*/
#include<bits/stdc++.h>
using namespace std;
struct N{
int sum;
int a;
int b;
};
bool asc(N n1,N n2){
return n1.sum>n2.sum;
}
int main() {
int n;
cin >> n;
N x[n];
for(int i=0;i<n;i++){
int a,b;
cin >> a >> b;
x[i].sum=a*a+b*b;
x[i].a=a;
x[i].b=b;
}
sort(x,x+n,asc);
cout << x[1].a << " " << x[1].b << endl;
}
Last updated
Was this helpful?