HDU 1005 STL map的运用
来源:互联网 发布:医疗器械 知乎 编辑:程序博客网 时间:2024/04/28 23:33
地址:http://acm.hdu.edu.cn/showproblem.php?pid=1005
题意:给你N个字符串,要你输出出现次数最多一个字符串;
思路:直接使用map。使用一个迭代器iterate,遍历一遍map,之后输出就可以了
代码如下:(不懂的可以加我QQ:756925010)
#include<iostream>#include<map>#include<string>using namespace std;int n;map<string, int> my_map;map<string, int>::iterator iter;string a;int main(){while (scanf("%d", &n) != EOF &&n){//my_map的初始化my_map.clear();//输入for (int i = 0; i < n; i++){cin >> a;my_map[a]++;}int len = my_map.size();int max = -1;//用了一个map的迭代器//注意iter是一个指针。//刚开始用的时候不知道,写出来的时候VS一直报错~~//还有就是begin和end的运用for (iter=my_map.begin();iter!=my_map.end(); iter++){if (max < iter->second){a = iter->first;max = iter->second;}}cout << a << endl;}return 0;}
0 0
- HDU 1005 STL map的运用
- hdu 4585 STL map 的运用
- HDU 4287 Intelligent IME(STL 映射map的运用)
- STL : map函数的运用 --- hdu 4941 : Magical Forest
- STL之Map的运用
- hdu 4941map的运用
- 正确运用stl map的erase方法
- 正确运用stl map的erase方法
- 正确运用stl map的erase方法
- 正确运用stl map的erase方法
- 正确运用stl map的erase方法
- UVa 156 STL之map的运用
- hdu 4941 Magical Forest(STL map & 结构体运用)
- 正确运用stl map的erase方法(转)
- poj 3481 Double Queue STL中map的运用
- codeforces 482 B Interesting Array <STL map 的运用>
- UVA12096,STL stack和set,Map的综合运用
- hdu 2648(Shopping) STL map的使用
- iOS中的单例
- 调用相机,选择图片上传,带预览功能
- strlen 实现
- Django 开启 服务提示错误error 10013
- Log4j自定义Appender介绍
- HDU 1005 STL map的运用
- eclipse不能自动编译生成class文件的解决办法
- 【Android入门】JSON介绍
- openwrt 1407改IP
- Android如何查看应用签名信息
- 体绘制算法
- WWDC总结:开发者需要知道的iOS 9 SDK新特性
- android webview加载网页
- 自定义UITableView折叠效果