hdu What Are You Talking About(map)

本文介绍了一道使用C++ STL map解决的问题(HDU 1075),并给出了详细的代码实现。通过该实例展示了如何利用map进行字符串映射,适用于初学者了解map的基本操作。

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1075

 

map简单应用

 

代码:

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <math.h>
 4 #include <algorithm>
 5 #include <iostream>
 6 #include <ctype.h>
 7 #include <iomanip>
 8 #include <queue>
 9 #include <map>
10 #include <stdlib.h>
11 using namespace std;
12 
13 int main()
14 {
15     char b[12],s1[12],s2[12],ch;
16     map<string,string> mp;
17     int d=0;
18     gets(b);
19     while(scanf("%s%s",s1,s2),strcmp(s1,"END")){
20         mp[s2]=s1;
21     }
22     getchar();
23     while(scanf("%c",&ch)){
24         if(isalpha(ch))
25             b[d++]=ch;
26         else{
27             b[d]='\0';d=0;
28             if(strcmp(b,"END")==0)
29                 break;
30             if(mp.find(b)!=mp.end())
31                 cout<<mp[b];
32             else
33                 printf("%s",b);
34             putchar(ch);
35         }
36     }
37 }

map学习链接:http://www.cnblogs.com/tianfang/archive/2006/12/30/607859.html

                    http://blog.youkuaiyun.com/yu_yuan_1314/article/details/9794435

                    http://blog.youkuaiyun.com/sanwenyublog/article/details/18006749

转载于:https://www.cnblogs.com/wangmengmeng/p/4871717.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值