题目来源 https://csacademy.com/ieeextreme-practice/task/c787255968c972c653677a52599ecc2f/statement/
题目
Elementary
Time limit: 1000 ms
Memory limit: 128 MB
Write a program that converts a word in the English dictionary (a string of lower case letters) into a number. Below are some examples of input-output pairs and there is a server that can give you more outputs for given inputs.
Your task is to find out what the functions does and program it.
Standard input
On the first line there will be an integer nn, the number of lines that will follow.
Lines 2, ..., n + 1 will contain one word on each one.
Standard output
Print a list of nn numbers, one per line.
For the given tests, each number will be smaller or equal to 10^6106.
Input Output 15 ieeextreme one brainteaser snow unicorn laparoscopy overcautiousness cosmos conclusion wisconsin binationalism barbascos cacophonic inosculate pneumonoconiosis 0 1 2 3 4 5 6 7 8 9 10 11 12 13 48 6 monkey frog bison chinook puffin rhinoceros 0 1 2 3 4 6 5 kale asparagus broccoli spinach chocolate 0 1 2 3 4
代码
映射关系一直没能找到,只能从github上找到了C++版本的代码,能运行通过,代码如下。映射关系到底是怎么找到的啊
C++(From Github)
#include <bits/stdc++.h>
using namespace std;
const int N = 26;
int dua[N][N] = {0,0,1,0,0,0,1,0,0,0,0,1,1,0,0,0,0,1,1,1,1,0,0,0,0,0,1,1,1,0,1,1,0,2,2,0,2,0,0,1,1,1,0,1,1,0,1,1,1,0,1,0,1,1,1,1,1,2,0,1,1,0,1,1,1,2,2,1,0,1,2,0,2,1,1,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,0,0,0,0,0,0,1,1,0,1,1,0,1,1,0,1,1,1,1,1,1,0,1,1,0,1,1,1,0,1,0,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,2,1,1,1,0,1,0,0,1,2,1,0,0,2,0,1,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,2,1,1,0,1,1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0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},{1,1},{1,0},{1,1},{0,1},{0,1},{0,0},{0,1},{0,0}}
,{{1,0},{0,1},{0,1},{0,0},{1,0},{0,1},{0,0},{1,1},{1,1},{0,0},{1,1},{0,0},{0,0},{0,1},{0,1},{0,1},{0,0},{1,0},{0,1},{0,0},{0,1},{0,1},{0,1},{0,0},{0,1},{0,0}}
,{{1,0},{0,1},{0,1},{1,0},{1,0},{1,1},{0,0},{0,1},{0,1},{0,0},{0,1},{1,0},{1,0},{1,1},{1,1},{0,1},{0,0},{1,0},{1,1},{0,0},{1,1},{0,1},{0,1},{0,0},{0,1},{0,0}}
,{{0,0},{1,1},{0,1},{0,0},{0,0},{0,1},{0,0},{0,1},{0,1},{0,0},{0,1},{0,0},{0,0},{0,1},{0,1},{0,1},{0,0},{0,0},{1,1},{0,0},{0,1},{0,1},{0,1},{0,0},{1,1},{0,0}}
,{{0,0},{0,1},{0,1},{0,0},{0,0},{0,1},{0,0},{0,1},{0,1},{0,0},{0,1},{0,0},{0,0},{0,1},{0,1},{0,1},{0,0},{1,0},{1,1},{0,0},{1,1},{0,1},{0,1},{0,0},{0,1},{0,0}}
,{{0,0},{0,1},{0,1},{0,0},{1,0},{0,1},{0,0},{0,1},{0,1},{0,0},{0,1},{1,0},{1,0},{0,1},{0,1},{0,1},{0,0},{1,0},{0,1},{0,0},{0,1},{0,1},{0,1},{0,0},{0,1},{0,0}}
,{{1,0},{0,1},{0,1},{1,0},{1,0},{0,1},{0,0},{0,1},{0,1},{0,0},{0,1},{0,0},{0,0},{0,1},{0,1},{0,1},{0,0},{0,0},{0,1},{0,0},{0,1},{0,1},{0,1},{0,0},{0,1},{0,0}}
,{{0,0},{0,1},{0,1},{0,0},{1,0},{1,1},{1,0},{0,1},{0,1},{0,0},{0,1},{0,0},{0,0},{0,1},{1,1},{0,1},{0,0},{0,0},{1,1},{0,0},{0,1},{0,1},{0,1},{0,0},{0,1},{0,0}}
,{{0,0},{0,1},{0,1},{0,0},{0,0},{0,1},{0,0},{0,1},{0,1},{0,0},{0,1},{0,0},{0,0},{1,1},{0,1},{0,1},{0,0},{1,0},{0,1},{0,0},{0,1},{0,1},{0,1},{0,0},{0,1},{0,0}}
,{{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1}}
,{{0,0},{0,1},{0,1},{0,0},{0,0},{0,1},{0,0},{0,1},{0,1},{0,0},{0,1},{0,0},{0,0},{0,1},{0,1},{0,1},{0,0},{1,0},{0,1},{0,0},{0,1},{0,1},{0,1},{0,0},{0,1},{0,0}}
,{{1,0},{0,1},{0,1},{0,0},{0,0},{0,1},{0,0},{0,1},{1,1},{0,0},{0,1},{0,0},{0,0},{0,1},{0,1},{0,1},{0,0},{1,0},{0,1},{0,0},{1,1},{1,1},{0,1},{0,0},{0,1},{0,0}}
,{{0,0},{0,1},{1,1},{1,0},{0,0},{0,1},{1,0},{0,1},{0,1},{0,0},{0,1},{0,0},{0,0},{1,1},{1,1},{0,1},{0,0},{0,0},{0,1},{1,0},{0,1},{0,1},{0,1},{0,0},{0,1},{0,0}}
,{{1,0},{1,1},{0,1},{1,0},{1,0},{0,1},{0,0},{1,1},{1,1},{0,0},{0,1},{0,0},{0,0},{0,1},{1,1},{1,1},{0,0},{0,0},{0,1},{0,0},{0,1},{0,1},{0,1},{0,0},{0,1},{0,0}}
,{{0,0},{0,1},{0,1},{0,0},{0,0},{0,1},{1,0},{0,1},{0,1},{0,0},{0,1},{0,0},{0,0},{0,1},{0,1},{0,1},{0,0},{0,0},{1,1},{0,0},{0,1},{0,1},{0,1},{0,0},{0,1},{0,0}}
,{{1,0},{1,1},{0,1},{1,0},{0,0},{0,1},{0,0},{0,1},{0,1},{0,0},{0,1},{0,0},{1,0},{0,1},{1,1},{0,1},{0,0},{1,0},{0,1},{1,0},{1,1},{0,1},{0,1},{0,0},{0,1},{0,0}}
,{{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1}}
,{{1,0},{1,1},{0,1},{0,0},{1,0},{1,1},{1,0},{1,1},{0,1},{0,0},{0,1},{0,0},{0,0},{1,1},{0,1},{0,1},{0,0},{0,0},{0,1},{0,0},{1,1},{0,1},{0,1},{0,0},{0,1},{0,0}}
,{{0,0},{1,1},{1,1},{0,0},{1,0},{0,1},{1,0},{0,1},{1,1},{0,0},{0,1},{0,0},{1,0},{1,1},{0,1},{0,1},{0,0},{1,0},{0,1},{0,0},{0,1},{0,1},{0,1},{0,0},{0,1},{0,0}}
,{{1,0},{1,1},{1,1},{0,0},{1,0},{0,1},{0,0},{1,1},{1,1},{0,0},{0,1},{1,0},{1,0},{0,1},{0,1},{0,1},{0,0},{0,0},{1,1},{0,0},{0,1},{0,1},{0,1},{0,0},{0,1},{0,0}}
,{{0,0},{0,1},{0,1},{0,0},{0,0},{0,1},{0,0},{0,1},{0,1},{0,0},{0,1},{0,0},{0,0},{0,1},{0,1},{0,1},{0,0},{0,0},{0,1},{0,0},{0,1},{0,1},{0,1},{0,0},{0,1},{0,0}}
,{{0,0},{0,1},{0,1},{0,0},{0,0},{0,1},{0,0},{0,1},{0,1},{0,0},{0,1},{0,0},{0,0},{0,1},{0,1},{0,1},{0,0},{0,0},{0,1},{0,0},{0,1},{0,1},{0,1},{0,0},{0,1},{0,0}}
,{{0,0},{1,0},{1,0},{0,0},{0,0},{1,0},{0,0},{1,0},{1,0},{0,0},{1,0},{0,0},{0,0},{1,0},{1,0},{1,0},{0,0},{0,0},{1,0},{0,0},{1,0},{1,0},{1,0},{0,0},{1,0},{0,0}}
,{{-1,-1},{-1,-1},{-1,-1},{-1,-1},{1, 0},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1}}
,{{0,0},{1,1},{0,1},{0,0},{0,0},{0,1},{0,0},{0,1},{0,1},{0,0},{0,1},{0,0},{0,0},{0,1},{0,1},{0,1},{0,0},{0,0},{0,1},{0,0},{0,1},{0,1},{0,1},{0,0},{0,1},{0,0}}
,{{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{1, 0},{-1,-1},{-1,-1},{-1,-1},{1,0},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1}}
};
const int M = 3e6 + 6;
int dp[M];
string tes[M];
bool calc(string s) {
int m = s.size();
for (int j = 0; j < m; j++)
s[j] -= 'a';
dp[0] = 0;
dp[1] = satu[s[0]];
if (m > 1)
dp[2] = dua[(s[0])][s[1]];
for (int j = 3; j <= m; j++) {
if (rule[s[j-2]][s[j-1]][0] == -1 || rule[s[j-2]][s[j-1]][1] == -1) dp[j] = 0;//return false;
else
dp[j] = dp[j-2] * rule[s[j-2]][s[j-1]][0] + dp[j-1] * rule[s[j-2]][s[j-1]][1];
}
return true;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
assert(calc(s));
cout << dp[s.size()] << endl;
}
return 0;
}
运行结果
看看别人代码的运行结果,再看看上道题自己的运行结果...