您的位置:首页 > 其它

【HDOJ】1075 What Are You Talking About

2014-04-02 17:08 387 查看
map,STL搞定。

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

#define MAXN 3005

char buf[MAXN], word[15];

int main() {
map<string, string> dict;
map<string, string>::iterator it;
int i, j;

scanf("%*s");   // START
while (scanf("%s", buf)!=EOF && strcmp(buf, "END")) {
scanf("%s", word);
dict[word] = buf;
}

scanf("%*s%*c");   // START
while (gets(buf)!=NULL && strcmp(buf, "END")) {
for (i=0, j=0; i<strlen(buf); ++i) {
if (buf[i]>='a' && buf[i]<='z') {
word[j++] = buf[i];
} else {
// If there is a valid word, find in dict.
if (j) {
word[j++] = '\0';   // add '\0'
it = dict.find(word);
if (it != dict.end())
printf("%s", (*it).second.data());
else
printf("%s", word);
j = 0;
}
printf("%c", buf[i]);
}
}
printf("\n");
}

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