需要先了解
#if 0
#include<bits/stdc++.h>
using namespace std;
int main() {
cout << "--------------1----------" << endl;
cout << setw(3) << 1 << setw(3) << 10 << setw(3) << 100;
cout << endl;
cout << setw(3) << 1 << 10 << setw(3) << 100 << endl;
cout <<"--------------2----------" << endl;
double a=9.235, b=6.5937;
cout << a << fixed << setprecision(1) << " " << b << endl;
cout << a << fixed << setprecision(1) << " " << b << endl;
int num = 100;
double num3 = 9.235325;
cout << num << endl;
cout << num3 << endl;
cout << "--------------3----------" << endl;
cout << num3 << endl;
cout<<setprecision(6);
cout << num3 << endl;
cout.unsetf(ios::fixed);
cout << num3 << endl;
cout << "--------------4----------" << endl;
double f = 3.123456789;
cout << f << endl;
cout << setprecision(2) << f << endl;
cout << fixed << f << endl;
cout << setprecision(2) << fixed << f << endl;
cout << fixed << setprecision(2) << f << endl;
}
#endif
代码
#if 1
#include<string>
using namespace std;
#include <iostream>
#include <iomanip>
#include<map>
int a,id;
double temp;
map<int, double>deal;
void func() {
cin >> a;
for (int i = 0; i < a; i++) {
cin >> id >> temp;
deal[id] += temp;
}
}
int main() {
func();
func();
for (auto i = deal.begin(); i != deal.end(); i++) {
if (i->second == 0)deal.erase(i);
}
cout << deal.size();
if (deal.size() != 0) {
for (auto i = deal.rbegin(); i != deal.rend(); i++) {
cout << " " << i->first <<fixed<<setprecision(1)<< " " << i->second;
}
}
return 0;
}
#endif