注册 登录
考研论坛 返回首页

sleeping1346的个人空间 http://home.kaoyan.com/?2907038 [收藏] [复制] [分享] [RSS]

日志

hdu1880-----map,string

已有 1658 次阅读2011-3-14 23:40 |个人分类:ACM入门学习|

关于字符串的,还是c++好用。

#include<iostream>
#include<string>
#include<map>
using namespace std;

map<string,string>m1;
map<string,string>m2;

int main()
{
    char s[120];
    string a,b,c;
    int n,i;
    while(gets(s),strcmp(s,"@END@")!=0)
    {
       c=s;
       i=c.find(']');
       a=c.substr(0,i+1);
       b=c.substr(i+2);
       m1[a]=b;
       m2[b]=a;
    }
    scanf("%d%*c",&n);
    while(n--)
    {
       gets(s);
if (s[0] == '[')
{
a = m1[s];
if (a == "") printf("what?\n");
else printf("%s\n", a.c_str());
}
else
{
a = m2[s];
if (a == "") printf("what?\n");
else printf("%s\n", a.substr(1, a.length() - 2).c_str());
}
    }
    return 0;
}


路过

雷人

握手

鲜花

鸡蛋
收藏 分享邀请 分享到人人 举报

评论 (0 个评论)

关于我们|商务合作|小黑屋|手机版|联系我们|服务条款|隐私保护|帮学堂| 网站地图|院校地图|漏洞提交|考研帮

GMT+8, 2024-5-6 19:11 , Processed in 0.050283 second(s), Total 8, Slave 8(Usage:3M, Links:[2]1,1_1) queries , Memcache On.

Powered by Discuz!

© 2001-2017 考研 Inc.

返回顶部
× 关闭