编程介的小学生 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 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题