ZeroJudge C381: Code of Bible

In the 1980s, mathematician Eliyahu Rips and physicist Doron Witstum of the Hebrew University of Jerusalem used high-speed computer calculations for a method called "equidistant letter sequences" to analyze the Hebrew Bible. They selected 32 prominent figures from Biblical times and found that their names, birth, and death dates were encoded together in the book of Genesis. They then removed all the spacing between words in the original Hebrew text of the Bible, creating a continuous string of 304,805 characters (based on the legend that Moses received the Bible from God "word by word, without any breaks"). Using computer skipping codes, they searched for names, words, and phrases in this string, ultimately finding a series of related information.

You've acquired another ancient document containing N words. Your task is to reconstruct the text where the words are connected "word by word". You also have M integers A1, A2, ..., and AM provided by the computer. You need to find the sequence of letters formed by combining the A1th, A2nd, ..., and AMth letters from this long string to form a word.

For example: The document you received is: "the quick brown fox jumps over the lazy dog." When connected into a long string: "thequickbrownfoxjumpsoverthelazydog." The clues provided by the computer are 33, 11, 34, 19, 21, 33, 30, 32. The word formed by combining these letters is: "doomsday."

Sample Inputs/Outputs

Sample Input(s)Sample Output(s)
EOF input. The first line of each test case consists of two positive integers N (N < 1000001) and M (M < 101).
The following N lines each contain an English word, with each word's length not exceeding 100 characters. The last line contains M positive integers separated by spaces, where each integer does not exceed the total length of the string.
When both N and M are 0, it indicates the end of the file, and this case should not be processed.
For each test case, please output the extracted text in one line.
9 8
the
quick
brown
fox
jumps
over
the
lazy
dog
33 11 34 19 21 33 30 32
0 0
doomsday

Thought Process

所有英文單字加到一個字串之後,在收數字時就將字串的那一位 -1 (因為測資是從 1 開始算) 輸出即可,最後換行。

Sample Code-ZeroJudge C381: Code of Bible

#include <iostream>
using namespace std;

int main() {
  int N, M;
  while (cin >> N >> M)
    {
      if (N == 0 && M == 0) break;
      string word = "";
      for (int i = 0; i<N; i++)
        {
          string str;
          cin >> str;
          word += str;
        }
      for (int i = 0; i<M; i++)
        {
          int tmp;
          cin >> tmp;
          cout << word[tmp-1];
        }
      cout << "\n";
    }
}

//ZeroJudge C381
//Dr. SeanXD

Comments