【HDOJ】1075 What Are You Talking About

时间:2022-03-22 09:18:49

map,STL搞定。

 #include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std; #define MAXN 3005 char buf[MAXN], word[]; 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=, j=; 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 = ;
}
printf("%c", buf[i]);
}
}
printf("\n");
} return ;
}