map

#include <iostream>
#include <string>
#include <map> //头文件
using namespace std;

map<string,int> my; //全局变量 0
map<string,int> ::iterator it ; //指针
int main( )
{

int i ;
string s1;
for(i=1; i<=5 ;i++)
{
cin>>s1;
my[s1]++;
}
for(it=my.begin() ; it!=my.end() ; it++ )
cout<<(*it).first <<" "<<(*it).second <<endl;
}

 

 


#include <iostream>
#include <string>
#include <map>
using namespace std;

map<string,int> my;
map<string,int> ::iterator it ;
int main( )
{

int i ;
string s1;
for(i=1; i<=5 ;i++)
{
cin>>s1;
my[s1]++;
}
for(it=my.begin() ; it!=my.end() ; it++ )
cout<<(*it).first <<" "<<(*it).second <<endl;

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

posted @ 2014-08-10 17:52  2014acm  阅读(136)  评论(0编辑  收藏  举报