内容:
说明:
示例代码:
// Maps_STL.cpp: 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <string>
#include <map>
using namespace std;
//by zhaocl
int main()
{
int n;
cin >> n;
map<string, int> st;
while( n-- )
{
int type;
cin >> type;
string name;
int marks;
switch( type )
{
case 1:
cin >> name >> marks;
if( st.find( name ) != st.end() )
st[name] = st[name] + marks;
else
st.insert( make_pair( name, marks ) );
case 2:
cin >> name;
st.erase( name );
case 3:
cin >> name;
if( st.find( name ) != st.end() )
cout << st[name] << endl;
else
cout << 0 << endl;
default:
break;
}
}
system( "pause" );
return 0;
}
知识点:
1、map容器作为c++中的键值对(即字典)的使用(插入、删除、查找)