注意:
1,先按次幂排序,then合并同次幂
2,赋值;a[]-->b[]-->c[]
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
struct st{
int x;
int y;
}a[5],b[5],c[5];
bool comp(st a,st b){
return a.y > b.y;
}
int main(){
for(int i = 1; i <= 4; i++){
cin >> a[i].x >> a[i].y;
}
b[1].x = a[1].x * a[3].x;
b[1].y = a[1].y + a[3].y;
b[2].x = a[1].x * a[4].x;
b[2].y = a[1].y + a[4].y;
b[3].x = a[2].x * a[3].x;
b[3].y = a[2].y + a[3].y;
b[4].x = a[2].x * a[4].x;
b[4].y = a[2].y + a[4].y;
sort(b+1,b+5,comp);
b[5].x = b[5].y = 0;
int p = 0;
for(int i = 1; i <= 4; i++){
if(b[i].y == b[i+1].y){
c[p].x = b[i].x + b[i+1].x;
c[p++].y = b[i].y;
i++;
}else {
c[p++] = b[i];
}
}
for(int i = 0; i < p; i++){
cout << c[i].x << " " << c[i].y <<endl;
}
return 0;
}