map映射容器

STL库里面的容器还是很好用的
比如说
priority_queue
vector

今天学一个map

定义:
map<数据类型,数据类型>容器名;

在这里插入图片描述
怎么记呢?背单词呗~英语书欢迎你

map型按first升序排序
加东西用(map<x,y>z)
z[add]=context;就行了

map的枚举:
map<x,y>::iterator I;
可以用I枚举了(欲写代码,先背单词)
放道题

在这里插入图片描述

#include<iostream.h>
#include<map>
using namespace std;
#define in Read()
#define re register
map<string,string>word;
char ch[50],a[50],b[50];
string st;

int main(){
	while(gets(ch)&&ch[0]!='\0'){
		sscanf(ch,"%s %s",a,b);
		word[b]=a;
	}
	while(cin>>st){
		if(word.find(st)!=word.end()){
			cout<<word[st]<<endl;
		}
		else cout<<"eh"<<endl;
	}
	return 0;
}
发布了26 篇原创文章 · 获赞 3 · 访问量 896

猜你喜欢

转载自blog.csdn.net/Antimonysbguy/article/details/103749236