mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
Create 1075_cnblogs_B.cpp
From http://www.cnblogs.com/qiufeihai/archive/2012/10/20/2732449.html
This commit is contained in:
parent
cf27523718
commit
65e14b0172
55
HDOJ/1075_cnblogs_B.cpp
Normal file
55
HDOJ/1075_cnblogs_B.cpp
Normal file
|
@ -0,0 +1,55 @@
|
|||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
char getChar[11];
|
||||
gets(getChar);
|
||||
char str1[33], str2[33];
|
||||
map <string, string> mp;
|
||||
map <string, string> :: iterator it;
|
||||
while (scanf("%s%s", str1, str2), str1[0] != 'E')
|
||||
{
|
||||
mp[str2] = str1;//可以传入char[]的地址
|
||||
}
|
||||
|
||||
getchar();
|
||||
char ansStr[3333];
|
||||
char saveStr[33];
|
||||
while (gets(ansStr), ansStr[0] != 'E')
|
||||
{
|
||||
int i;
|
||||
int k = 0;
|
||||
for (i = 0; i < strlen(ansStr); i++)
|
||||
{
|
||||
if (ansStr[i] < 'a' || ansStr[i] > 'z')
|
||||
{
|
||||
if (ansStr[i - 1] >= 'a' && ansStr[i - 1] <= 'z')
|
||||
{
|
||||
saveStr[k] = '\0';
|
||||
k = 0;
|
||||
it = mp.find(saveStr);
|
||||
if (it == mp.end())
|
||||
{
|
||||
printf("%s", saveStr);//字典中不存在,则输出原单词
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << it->second;//存在,输出翻译
|
||||
}
|
||||
}
|
||||
|
||||
printf("%c", ansStr[i]);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
saveStr[k++] = ansStr[i];
|
||||
}
|
||||
}
|
||||
puts("");
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user