Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SP-STL-02.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <fstream>
- #include <iterator>
- #include <map>
- using namespace std;
- map<int,unsigned int> statistic_map;
- map<int,unsigned int>::iterator m_iter;
- int _tmain(int argc, _TCHAR* argv[])
- {
- ifstream file("a.txt");
- istream_iterator<int> i(file);
- while (i!=istream_iterator<int>())
- {
- int key=*i++;
- m_iter=statistic_map.find(key);
- if (m_iter==statistic_map.end())
- {
- statistic_map.insert(make_pair(key,1));
- }
- else
- {
- unsigned int n=statistic_map[key];
- statistic_map[key]=n+1;
- }
- }
- for (m_iter=statistic_map.begin();
- m_iter!=statistic_map.end(); m_iter++)
- {
- cout << m_iter->first << " " << m_iter->second<< endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement