Write before:
1. This code cannot pass OJ, even if you use the code accepted in 2016, OJ still cannot pass;
2. This code is output in strict accordance with the format of sample output. There is no newline after the last line is unknown, resulting in bloated code. If you don't care about the format, you can delete 2 / 3 of the output code;
Description:
Night Fury is a very rare and most dangerous and intelligent dragon from "master of dragon training 2". It is very different from other dragons in shape. It is similar to bats. At the same time, it combines the size of cats and the sharp eyes of wild wolves, with black scales on its body. The volume is petite, the expression and action are smart and lovely, and the ratio of wings is the largest in the dragon. There are up to three pairs of wings, so the flight time is longer, the speed is faster and more flexible. Different from the flame erupted by other dragons, it is a blue ball accompanied by calcium carbide gas and oxygen. It explodes after impact or flying for a certain distance. It has accurate attack, superb fighting skills, high intelligence, small size and superior flight and attack ability.
Now, as a young and brave Viking warrior, burp burp, you have a night evil named toothless boy. In order to know what toothless is thinking, you need to go into its world. Because toothless babies have natural super powers, there is a special mathematical definition in the toothless world. For example, "1" = "5", "2" = "6", "3" = "7", "4" = "8".
At this time, toothless asked you a question, how much is 5? For a moment, you can't remember. After thinking for a long time, you know, "5" = "9". You suddenly feel very embarrassed.
Now, the question comes. Toothless will describe the mathematical definition of its world with you. You need to answer its questions one by one.
Input:
Enter a T, indicating that there are t groups of test data. Enter an n (0 < n < = 106) to indicate that there are n equations, and then enter n-line equations (a=b, a and b are integers, 0 < a < 105,0 < b < 10 ^ 5),
Enter an M, and then enter m numbers, indicating the number to query. (a = b,b = c will not occur)
Output:
Output m numbers, indicating the corresponding number of the number to be queried. If the number to be queried does not appear, output unknown. There is a blank line between each two sets of data.
Sample Input:
2
1
1=2
2
1
2
2
5=10
7=8
3
5
7
1
Sample Output:
2
1
10
8
UNKNOW
#include <iostream> #include "string" #include "vector" using namespace std; /** *Toothless world * @return */ int main() { int t; cin >> t; for (int i = 0; i < t - 1; ++i) { int n, m; cin >> n; //Filling equation vector<vector<string>> equation(n); for (int j = 0; j < n; ++j) { string str; cin >> str; int pos = str.find("=", 0); string first = (str.substr(0, pos)); string end = (str.substr(pos + 1, str.length() - pos)); equation[j].push_back(first); equation[j].push_back(end); } cin >> m; //Collect the numbers you need to find vector<string> compare; for (int j = 0; j < m; ++j) { string comp; cin >> comp; compare.push_back(comp); } //Judgment result for (int j = 0; j < m; ++j) { string result = "UNKNOW"; for (int k = 0; k < n; ++k) { if (compare[j] == equation[k][0]) { result = (equation[k][1]); } if (compare[j] == equation[k][1]) { result = (equation[k][0]); } } cout << result << endl; } } cout << endl; int n2, m2; cin >> n2; //Filling equation vector<vector<string>> equation(n2); for (int j = 0; j < n2; ++j) { string str; cin >> str; int pos = str.find("=", 0); string first = (str.substr(0, pos)); string end = (str.substr(pos + 1, str.length() - pos)); equation[j].push_back(first); equation[j].push_back(end); } cin >> m2; //Collect the numbers you need to find vector<string> compare; for (int j = 0; j < m2; ++j) { string comp; cin >> comp; compare.push_back(comp); } //Judgment result for (int j = 0; j < m2 - 1; ++j) { string result = "UNKNOW"; for (int k = 0; k < n2; ++k) { if (compare[j] == equation[k][0]) { result = (equation[k][1]); } if (compare[j] == equation[k][1]) { result = (equation[k][0]); } } cout << result << endl; } for (int i = 0; i < n2; ++i) { if (compare[m2 - 1] == equation[i][0]) { cout << equation[i][1]; } if (compare[m2 - 1] == equation[i][1]) { cout << equation[i][0]; } } cout << "UNKNOW"; }