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;
}
#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;
}
相关文章推荐
- hdu 1075 What Are You Talking About
- hdu 1075 What Are You Talking About(HashMap水过,可用字典树)
- HDU 1075 - What Are You Talking About
- hdu 1075 What Are You Talking About(字典树)
- HDU 1075 What Are You Talking About // 字符串映射,Trie
- hdu 1075 What Are You Talking About(map)
- hdu 1075 What Are You Talking About
- HDU 1075 What Are You Talking About
- hdu 1075 What Are You Talking About(map)
- HDU 1075-What Are You Talking About(Trie)
- hdu 1075 What Are You Talking About
- hdu 1075 What Are You Talking About
- hdu 1075 What Are You Talking About
- hdu 1075 What Are You Talking About(Trie树)
- HDU 1075 What Are You Talking About
- HDU - 1075 - What Are You Talking About
- HDU1075——What Are You Talking About
- hdu 1075 What Are You Talking About
- HDU 1075 What Are You Talking About(map+字符串)
- hdu 1075 What Are You Talking About