您的位置:首页 > 其它

HDU 1075 What Are You Talking About

2012-09-25 21:20 525 查看
#include <iostream>

#include <string>

#include <map>

using namespace std;

int main()

{

map<string, string> dic;

map<string, string>::iterator pos; // 以数组方式插入

string a, b;

cin >> a;

while (true)

{

cin >> a;

if (a == "END") break;

cin >> b;

dic.insert(make_pair(b, a)); // 插入

}

getline(cin, a); // filter '\n'

getline(cin, a); // read "START\n"

while (true)

{

getline(cin, a); // 按每行输入输出

if (a == "END") break;

string::size_type i, len;

len = a.size();

b = ""; // b是空串

for (i = 0; i < len; ++i)

{

if (isalpha(a[i])) // a[i]是字母

{

b += a[i];

continue;

}

pos = dic.find(b);

if (pos != dic.end()) // 能在字典树中找到

cout << pos->second; // 存储的数据。 ->first 代表关键字

else

cout << b;

cout << a[i];

b = "";

}

cout << endl;

}

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: