map容器

hdu 1880

http://acm.hdu.edu.cn/showproblem.php?pid=1880

我用MAP做了下,或许还有更简单的方法。。

code:

#include <iostream>
#include "cstdio"
#include "map"
using namespace std;
int main(int argc, char *argv[])
{
	char szhong[105];
	map <string,string> m;		//map字典 
	map <string,string> m2;
	map <string,string>::iterator iter;
	while(gets(szhong))
	{
		string sz;
		sz=szhong;
		if(sz=="@END@")
		{
			break;
		}
		int i;
		char zhouyu[25],gongneng[85];
		int zweizhi=0;
		int gweizhi=0;
		for(i=0;;i++)
		{
			if(sz[i]==']')
			{
				break;
			}
			zhouyu[zweizhi]=sz[i];
			zweizhi+=1;
		}
		zhouyu[zweizhi]=']';
		zweizhi+=1;
		zhouyu[zweizhi]='\0';
		string zy=zhouyu;
		int i2;
		for(i2=i+2;i2<sz.length();i2++)
		{
			gongneng[gweizhi]=sz[i2];
			gweizhi+=1;
		}
		gongneng[gweizhi]='\0';
		string gn=gongneng;
		//cout<<zy<<endl;
		m[zy]=gn;
		m2[gn]=zy;
	}
	//----------------开始问题------------ 
	
	int q;
	cin>>q;
	int i;
	getchar();
	for(i=0;i<q;i++)
	{
		char qqc[105];
		
		gets(qqc);
		string qq;
		qq=qqc;
		//cout<<qq<<endl;
		
		if(qq[0]=='[')
		{
			if(m[qq]!="")
			{
				cout<<m[qq]<<endl;
			}else
			{
				cout<<"what?"<<endl;
			}
				
		}else			//输入的是功能 
		{
			if(m2[qq]!="")
			{
				int ir;
				for(ir=1;ir<m2[qq].length()-1;ir++)
				{
					cout<<m2[qq][ir];
				}
				cout<<endl;
				
			}else
			{
				cout<<"what?"<<endl;
			}
		}
		
	}
	return 0;
}

 

 

 

你可能感兴趣的:(map容器)