hdu 1029 Ignatius and the Princess IV //map的使用
2015-03-08 11:14
357 查看
#include <cstdio> #include <algorithm> #include <map> #include <vector> using namespace std; int main() { int n, i, k; map<int, int>a; while(scanf("%d", &n) != -1){ for(i=0; i<n; i++){ scanf("%d", &k); /* if(a.count(k)==0){ a.insert(pair<int, int>(k, 1)); //map的插入, count()是返回key出现的次数,在map里,key只能是0和1 } else*/ a[k]++; //会自动判断是否存在key k,存在则++, 不存在则插入后初始化后++ } map<int, int>::iterator pos; for(pos=a.begin(); pos!=a.end(); pos++){ if(pos->second >= (n+1)/2){ printf("%d\n", pos->first); break; } } a.clear(); } return 0; }
相关文章推荐
- hdu 1029 Ignatius and the Princess IV(水题,map)
- HDU1029——Ignatius and the Princess IV
- hdu 1029 Ignatius and the Princess IV
- hdu 1029 Ignatius and the Princess IV
- hdu-oj 1029 Ignatius and the Princess IV
- hdu 1029 ( Ignatius and the Princess IV ) 水题
- HDU 1029 Ignatius and the Princess IV 【求众数】
- hdu_1029-Ignatius and the Princess IV_201310180916
- HDU 1029 Ignatius and the Princess IV
- HDU 1029 Ignatius and the Princess IV
- hdu 1029 Ignatius and the Princess IV
- HDU_1029 Ignatius and the Princess IV
- Ignatius and the Princess IV hdu 1029
- HDU 1029 Ignatius and the Princess IV
- HDU—— 1029 Ignatius and the Princess IV
- HDU 1029 Ignatius and the Princess IV
- hdu 1029 Ignatius and the Princess IV
- Ignatius and the Princess IV hdu 1029
- HDU1029——Ignatius and the Princess IV
- [ACM] hdu 1029 Ignatius and the Princess IV (动归或hash)