0065 - Trading
#include <algorithm> #include <cstdio> #include <cstdlib> #include <iostream> #include <map> #include <string> using namespace std; void Slove(void) { string s; map<int,int> before, next; while ( getline(cin,s) ) { if ( s.empty() ) break; int number=atoi( s.c_str() ); if ( !before.count(number) ) before.insert( map<int,int>::value_type(number,1) ); else ++before.find(number)->second; } while ( getline(cin,s) ) { int number=atoi( s.c_str() ); if ( before.count(number) ) if ( !next.count(number) ) next.insert( map<int,int>::value_type(number,before.find(number)->second+1) ); else ++next.find(number)->second; } for (map<int,int>::iterator it=next.begin(); it!=next.end(); ++it) cout << it->first << " " << it->second << endl; } int main(void) { Slove(); return 0; }
やるだけ。。