# Title: Translation

## Content:  # Problem solving analysis:

It seems that the input and output format of this question is not very clear,
1) all data may be input, and then output (solution 1, memory may not be enough, high universality of the topic (AC pass))
2) it is also possible to output a line of results immediately after the data to be tested is input (solution 2, memory can, because the meaning of the question is ambiguous, it may not be solved (failed))
Both writing methods have been written, and finally passed in the first input and output format. Fortunately, the background data has not exceeded the memory

# Solution code:

## Solution 1 (AC):

```//Solution 1: the memory may not be enough, so it has high generality for the topic (passed by AC)
#include<iostream>
#include<map>
#include<cstdio>
using namespace std;
int main() {
string s, s0, s1 = "", s2 = "";
map<string, string> f;
f["czy"] = "cml";
cin >> s1;
while(s2 != "BEGIN") {
cin >> s1 >> s2;
f[s2] = s1;
}
int n = 0;
char ch;
do {
cin >> s[++n];
ch[n] = getchar();
}while(s[n] != "END");
for(int i = 1; i < n; i++) {
s0 = "";
for(int j = 0; j < s[i].size(); j++) {
if(s[i][j] >= 'a' && s[i][j] <= 'z') {
s0 += s[i][j];
} else {
if(f[s0] != "") cout << f[s0];
else cout << s0;
cout << s[i][j];
s0 = "";
}
}
if(f[s0] != "") cout << f[s0];
else cout << s0;
if(ch[i] == '\n') cout << "\n";
else cout << " ";
}
}```

## Solution 2 (WA):

```//Solution 2, memory can, because the meaning of the question is ambiguous, it may not be so solved (failed)
#include<iostream>
#include<map>
#include<cstdio>
#include<cstring>
using namespace std;
int main() {
string s0, s1 = "", s2 = "";
map<string, string> f;
f["czy"] = "cml";
cin >> s1;
while(1) {
cin >> s1 >> s2;
if(s2 == "BEGIN") break;
f[s2] = s1;
}
char s;
getchar();
while(1) {
gets(s);
if(s == 'E' && s == 'N' && s == 'D') break;
s0 = "";
for(int i = 0; i < strlen(s); i++) {
if(s[i] >= 'a' && s[i] <= 'z') {
s0 += s[i];
} else {
if(f[s0] != "") cout << f[s0];
else cout << s0;
cout << s[i];
s0 = "";
}
}
cout << endl;
}
}```

From September 30, 2016 - Zhiyin

Tags: C++ PHP

Posted on Tue, 10 Dec 2019 11:25:42 -0800 by mdgalib