PAT1002
#include<iostream> #include<string> #include<sstream> #include<map> #include<vector> using namespace std; int main() { string s1, s2; while(getline(cin, s1) && getline(cin, s2)) { stringstream ss1, ss2; map<int, float> m; vector<pair<int, float> > vec; ss1.str(s1); ss2.str(s2); float i,j; ss1>>i; ss2>>i; float n1[11] = {0}, n2[11] = {0}; while(ss1>>i>>j) { m[(int)i] += j; } while(ss2>>i>>j) { m[(int)i] += j; } for(map<int, float>::reverse_iterator it = m.rbegin(); it != m.rend(); it++) { if((*it).second != 0) vec.push_back(*it); } cout<<vec.size(); for(int i = 0; i < vec.size(); i++) printf(" %d %.1f", vec[i].first, vec[i].second); } }