1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <map>	/*引用map头文件*/ 
#include <string>	/*C++ string头文件*/ 
using namespace std;
int main()
{
	/*
	le.clear() 	清空
	le.begin() 	起始的键
	le.end()	末尾键加一 
	le.size() 	返回容器的大小
	le.count( char C )	判断关键字是否出现, 返回值为0或1
	le.empty()	判断是否为空
	le.insert(pair<int,string>(102,"aclive"));	插入元素 
   	le.live.insert(map<int,string>::value_type(321,"hai"));
   	le.lower_bound()    返回键值>=给定元素的第一个位置
   	le.upper_bound()     返回键值>给定元素的第一个位置
   	swap()            交换两个map	用法 m1.swap( m2 ) ;
   	
   	le.find(char C)
	   	来定位数据出现位置,它返回的一个迭代器,
	   	当数据出现时,它返回数据所在位置的迭代器
	   	如果map中没有要查找的数据,它返回的迭代器等于M.end()函数返回的迭代器。
   	
	le.erase(const key_type&__x)	删除等于某个键值的元素
	le.erase(iterator __first,iterator __last)	删除一个迭代区间上的所有元素
	le.erase(iterator __positation)	删除某个迭代器位置上的元素 
	it = erase() 成员函数返回下一个元素的迭代器
	*/
	map<char,int> le;	/*定义一个map容器*/ 
	map<char,int> :: iterator  it;	/*map迭代器*/ 
	char ch;
	string str;	/*字符串指针*/ 
	string letter;	
	string::iterator i;	/*字符串迭代器*/ 
	
	/*abcdefghijklmnopqrstuvwxyz*/
	letter = "ABCDWFGHIJKLMNOPQRSTUVWXYZ";
	while( cin>>str ){
		for( i = letter.begin(); i != letter.end(); i++ ){
			le[*i];		/*在 le里添加一个*i的键,其值为0*/ 
		}
		for( i = str.begin(); i != str.end(); i++ ){
			if( *i >= 'A' && *i <= 'Z' )
				le[*i] ++;	/*访问到键后指向的值加一*/ 
			else
				le[*i-( 'a' - 'A' )] ++;
		}
		
		
		/*迭代器输出*/ 
		//le.erase( 'A' );	/*删除键为A的元素*/
		//le.erase( le.begin(), le.end() );
		if( le.empty() )
			printf("空\n");  
		for( it = le.begin(); it != le.end(); it++ ){
			cout<<it->first<<':'<<it->second<<endl; 	
		}
		if( le.count('A') )
			printf("YES le.count('A') = %d\n", le.count('A') );
		else
			printf("NO\n");
		le.clear();
	}
	 
	return 0;
}