IEEE xtreme 练习2: Ad Hoc-- Elementary

题目来源 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^610​6​​.

InputOutput
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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1,0},{0,1},{0,1},{0,0},{0,1},{1,0},{1,0},{0,1},{0,1},{0,1},{0,0},{1,0},{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;
}

运行结果

看看别人代码的运行结果,再看看上道题自己的运行结果...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

R.X. NLOS

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值