1370. Numerals of Przesmyks

单点时限: 2.0 sec

内存限制: 256 MB

In remote past there lived a tribe of Przesmyks (read it: “Pshaesmix”). They were outstanding, for those times, experts in numbers. To write numerals they used only two symbols, “+” and “-“, whose ritual meaning is still a subject for historians’ research. It is known that Przesmyks were able to write all natural numbers 0, 1, 2, … They used sequences of characters “+” and “-” to write numerals, but for religious reasons some of such sequences were forbidden. Every year priests announced how many “-” characters in a row maximally were allowed in notation of numerals. Depending on the year the bound was from 1 to 113. The way of notation of numerals was stated as follows: All legal sequences of “+” and “-” characters were ordered from shorter to longer ones, and sequences of the same length alphabetically (same as in in a dictionary, assuming “-” preceded “+”). Sequences ordered that way represented successive numbers 0, 1, 2, … For example if more than one “-” character in a row were not allowed, then the notation of numerals looked as follows:

0 -

1 +

2 -+

3 +-

4 ++

5 -+-

6 -++

7 +-+

8 ++-

9 +++

10 -+-+

11 -++-

The notation of numerals changed according to changes in the bound. For example, when two or more “-” characters in a row were allowed then the number 2 was written as “–“. The situation puts contemporary historians to a lot of trouble.

Task

Write a program which:

1.reads two bounds of maximal number of “-” characters in a row that may appear in the notation of numerals, and a set of numbers written in the notation of Przesmyks according to the first bound,

2.translates those numbers into the notation of Przesmyks according to the second bound,

3.writes the numbers in the new notation.

输入格式

In the first line of the standard input there are three positive integers m1, m2 and n, separated by single spaces, 1 <= m1,m2 <= 113, 1 <= n <= 10. The number m1 is the bound on the maximal number of “-” characters in a row that may appear in the notation of numerals in the input data. The number m2 is the bound on the maximal number of “-” characters in a row that may appear in the notation of numerals that have to be written out. The number n is the number of numerals that are to be converted. In the following n lines there are n numerals (strings of ‘-‘ and ‘+’), one per line. None of those numerals exceeds 1000 characters.

输出格式

Your program should write to the standard output. It should write in the successive lines the successive numbers from the input data translated into the notation of Przesmyks according to the bound m2 on the maximal number of “-” characters in a row.

样例

Input
1 2 3
-+-
-+
+-+
Output
++

0 人解决,1 人已尝试。

0 份提交通过,共有 5 份提交。

9.9 EMB 奖励。

创建: 17 年,3 月前.

修改: 7 年,2 月前.

最后提交: 3 年,12 月前.

来源: POI

题目标签