编程介的小学生 2016-12-25 11:25 采纳率: 20.5%
浏览 1002
已采纳

Computer DJ

Description

A very famous DJ has been recently invited to play in the closing party of a Computer Science conference. Trying to impress the participants of the event, he decided to use a program in order to choose the songs he would play at this party. However, the result was a disaster, since the way the program chose the songs was quite weird and repetitive.

First of all, the DJ has selected N songs among the set of songs he had available. The program used by the DJ then labels each of the songs using one different character from 'A' to 'Z'. The ith song is labeled using the ith character of the sequence 'A'-'Z'. The program chooses the songs to be played in the party in the order that their labels appear in the following infinite sequence of characters: first come all the words with one character in lexicographical order; then all the words with two characters in lexicographical order; then all the words with three characters in lexicographical order; and so on. For N = 3, this sequence would be ABCAAABACBABBBCCACBCCAAAAABAACABAABBABC...

At the end of the party, some people asked the DJ if he remembered which the first song played was. Others would like to know which the 25th was, and so on. The DJ remembers nothing but the strange pattern of repetition of the songs, so he urges you to help him and write a program which answers such queries.
Input

The input contains several test cases. Each test case consists of three lines. The first line of a test case contains two integers N and Q indicating respectively the number of songs chosen by the DJ and the number of queries made by the participants (1 <= N <= 26 and 1 <= Q <= 1000). In the second line, there will be the N titles of the songs (the title of a song is a chain of alphanumerical characters of at least one and at most 100 characters) separated by single spaces. The last line of a test case contains a sequence of queries. Each query is a number k (1 <= k <= 100000000) corresponding to the kth song played in the party. The end of the input is indicated by N = Q = 0.
Output

For each query number k in a test case, you shall print a single line containing the name of the kth song played in the party. A blank line must follow each test case.
Sample Input

10 3
S0 S1 S2 S3 S4 S5 S6 S7 S8 S9
3 6 10
3 5
Pathethique TurkishMarch Winter
1 2 3 4 16
0 0
Sample Output

S2
S5
S9

Pathethique
TurkishMarch
Winter
Pathethique
Winter

  • 写回答

1条回答

  • threenewbee 2016-12-28 15:26
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?