// Test.cpp : Defines the entry point for the console application. //
#include "stdafx.h" #include <iostream> #include <vector> #include <algorithm> using namespace std;
void show (int p) { ?? ?cout << p << endl; }
int main(int argc, char* argv[]) {
?? ?vector<int> c1; ? ? c1.push_back(1880); ? ? c1.push_back(650); ? ? c1.push_back(1120); ?? ?c1.push_back(950); ?? ?c1.push_back(1880);
?? ?for_each(c1.begin(),c1.end(),show);
?? ?//Statistics ?? ?while(!c1.empty()) ?? ?{ ?? ??? ?//count ?? ??? ?int num = ?count(c1.begin(),c1.end(),*(c1.begin())); ?? ??? ?cout<<"elem:" << *(c1.begin()) << "---" << "times: "<<num<<endl; ?? ??? ? ?? ??? ?//erase ?? ??? ?int tag = *c1.begin() ;?? ? ?? ??? ?while( num ) ?? ??? ?{ ?? ??? ??? ?for (vector<int>::iterator iter=c1.begin(); iter != c1.end();iter++) ?? ??? ??? ?{ ?? ??? ??? ??? ?if(*iter == tag ) ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?c1.erase(iter); ?? ??? ??? ??? ??? ?break; ?? ??? ??? ??? ?}?? ??? ??? ? ?? ??? ??? ?} ?? ??? ??? ?num--; ?? ??? ?}
?? ?} ?? ? ?? ?//printf("Hello World!\n"); ?? ?return 0; }
|