PowerOJ 2436: STL入门 unordered_map
来源:互联网 发布:部队网络保密教育 编辑:程序博客网 时间:2024/06/17 04:27
题目链接:点击打开链接
第一次使用unordered_map,有些情况比map效率高很多,特此记录
unordered_map和map的比较:链接1,链接2
我的
#include <iostream>#include <stdio.h>#include <unordered_map>#include <map>using namespace std;int main(){ int n; while(scanf("%d",&n) != EOF) { int cnt = 1; unordered_map<string,int> str; char s[15]; for(int i = 1; i <= n; i++) { scanf("%s",s); if(str.find(s) == str.end()) str[s] = cnt++; printf("%d\n",str[s]); } } return 0;}
#include<unordered_map>#include<cstdio>#include<cstring>#include<cstdlib>using namespace std;struct hash_func{ size_t operator()(char * const &a)const { size_t res = 0; for (char *s = a; *s; s++) res = res * 131 + *s; return res; }};struct equal_func{ bool operator()(char * const &a, char * const &b)const { return strcmp(a, b) == 0; }};int main(){ int n; while (~scanf("%d", &n)) { unordered_map<char *, int, hash_func, equal_func> m; int cnt = 1; while (n--) { char *s; s = new char[11]; scanf("%s", s); if (m.find(s) == m.end()) m[s] = cnt++; printf("%d\n", m[s]); } for (auto &i : m) delete[] i.first; }}
0 0
- PowerOJ 2436: STL入门 unordered_map
- STL学习----入门(1)[unordered_map]
- STL---哈希map:unordered_map
- STL unordered_map(hash_map)详解
- STL之unordered_map
- STL map与Boost unordered_map
- STL::unordered_map之无序map
- STL map与Boost unordered_map
- STL map与Boost unordered_map
- STL map与Boost unordered_map
- STL map与Boost unordered_map
- STL map与Boost unordered_map
- STL map与Boost unordered_map
- STL map与Boost unordered_map
- STL::map mutil_map unordered_map 小结
- STL map与Boost unordered_map
- STL map与Boost unordered_map
- STL map与Boost unordered_map
- 子串匹配KMP算法
- Ubuntu下安装配置Hadoop
- 最小二乘法
- 经典冒泡排序算法JAVA版本
- 静态链接库与动态链接库的区别
- PowerOJ 2436: STL入门 unordered_map
- Java System
- Seven More Languages in Seven Weeks (读书笔记):miniKaren
- adb用法
- UVa455 Periodic Strings
- 图片轮播
- 正则表达式30分钟入门教程
- json工具类
- Git常用命令