通过迭代器来获得对应元素的下标╮(╯▽╰)╭ ~
2016-07-24 19:13
218 查看
#include <iostream> #include <cstdio> #include <vector> #include <map> #include <set> #include <string> #include <cstring> #include <cstdlib> #include <cmath> #include <utility> #include <algorithm> using namespace std; map<int, int> m; map<int, int> :: iterator it, firs, e; vector <int> v; int a[15]; int main() { for (int i=0; i<=10; i++) { a[i] = i; v.push_back (i); m[i]++; } for (it=m.begin(); it!=m.end(); it++) { cout << it->first << " " << it->second << endl; } firs = m.begin(); e = m.end(); cout << distance(firs, e) << " ~~ " << a[distance(firs, e)-1] << " ~~ " << a[(int)m.size()-1]<< endl; //高能预警:如果下面一行第二个输出是a[distance(v.begin(), v.end())-1]就对啦 cout << distance(v.begin(), v.end()) << " ~~ " << a[distance(v.begin(), v.end())] << endl; return 0; }
相关文章推荐
- Python开发柜员机系统
- Effective Java 创建和销毁对象
- Android自定义Animation实现3D翻转按钮
- 线程 —— 使用匿名内部类的方式启动线程
- [算法学习笔记]线性时间排序----计数排序
- 用C语言查询某个人的投票数
- 测试
- 调整数组顺序使奇数位于偶数前面
- java反射机制
- XML——XSL 样式单文档
- 关闭游览器后, php程序还会执行吗?
- 两次BC反思
- (static)静态代码块,非静态代码块和构造函数
- 线程 —— 通过 Callable 对象创建线程
- xcode少有人知的宏定义
- XML——XML的那些事
- POJ 3080 Blue Jeans (很暴力)
- MySQL--连接属性
- UVa 12100 Printer Queue(习题5-7)
- iOS中 Realm的学习与使用 韩俊强的博客