题目链接: http://codeforces.com/problemset/problem/864/A
题目描述: 看不是是不是一串数中只有两种数且这两种数字的数量是相同的
解题思路: 水题, 水过去
代码:
#include <iostream> #include <cstdio> #include <map> #include <iterator> using namespace std; map<int, int > m; int main() { int n; cin >> n; int cnt = 0; for( int i = 0; i < n; i++ ) { int num; cin >> num; if( m[num] == 0 ) cnt++; m[num]++; } if( cnt == 2 ) { map<int, int>::iterator it; it = m.begin(); int temp = it->second; int ans = it->first; it++; if( temp == it->second ) { cout << "YES" << endl; cout << ans << " " << it->first << endl; } else { cout << "NO" << endl; } } else { cout << "NO" << endl; } return 0; }
思考: 十分钟做出来的......读题读了六分钟, 真的菜
http://codeforces.com/problemset/problem/864/A