Sphere Online Judge



SPOJ Problem Set (classical)

94. Numeral System of the Maya

Problem code: MAYA

The Maya lived in Central America during the first millennium. In many regards, they consituted one of the most developed and most fascinating cultures of this epoch. Even though draught animals and the wheel were unknown to the Mayas, they excelled in the fields of weaving, architecture and pottery. But truely breath-taking were their achievements in the fields of astronomy and mathematics. Whilst Europe was trudging through the dark Middle Ages, the Maya determined the solar year to 365.242 days (modern-day measurement: 365.242198) and the lunar cycle to 29.5302 days (modern-day measurement: 29.53059). Such astonishingly precise findings were hardly possible without a powerful numeral system. In this task we will explore the Maya's numeral system.

Maya priests and astronomers used a numerical system to the base of 20. Unusual to their time, their system also included the concepts of digits and of the zero. Both concepts were completely unknown to the Europeans at this time. The first nineteen numbers of the vigesimal system were represented by dots and dashes according to the following table:

The zero was written down as a symbol resembling a shell. Multi-digit numbers (i.e. the numbers bigger than 19) were written in vertical arrangement, with the highest-value digit on top. For example, the number 79 was written as

As can be seen, the second digit possesses a value of 20.

Due to an interference of the two calendar systems of the Maya, the third digit did not hold the value 400 (20x20), as would be expected, but 360. All the following digits were again treated regularly, i.e. the fourth digit counted 7200 (360x20), the fifth 144000 (7200x20), and so on.

Hence, the number 13495 (=1x7200+17x360+8x20+15) was written as follows:

Write a program to convert Maya numbers to decimal numbers!

Input

The input file contains a list of numbers written down in Maya fashion. Of course, dots are represented as points (.), and dashes are represented as hyphens (-). The zero digit, the shell symbol, is written as a capital letter S (S). Description of a Maya number starts with n - the number of the Maya digits. The following n lines contain one digit each. One digit is written from top to bottom using spaces as vertical separators.

One number will not have more than seven digits. Each two numbers are separated by a blank line. Input terminates with n = 0

Output

Your program has to output the value of the number in the input file in the nowadays more common decimal system. One number per line.

Example

Sample input:
1
..

5
... -
. - -
S
S
S

0
Sample output:
2
1231200

Added by:Micha³ Czuczman
Date:2004-07-11
Time limit:3s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel Pentium G860 3GHz)
Languages:All except: NODEJS PERL 6
Resource:Swiss Olympiad in Informatics 2004

hide comments
2014-05-25 22:03:00 Ashish Gaurav
AC!
2013-09-07 09:22:05 Aswin Murugesh
For Languages like Python, Don't forget the "Blank line" after each test case
2013-07-09 10:33:38 Rishabh Dugar
although gets() is not recommended,,,it wrks fine if u eat up the newline with getchar...
2013-06-12 15:26:16 ওয়াসী (Wasi)
@Prikshit Kumar Yap! there is a space between every digit(after dots and between dashes)

Last edit: 2013-08-21 14:54:20
2013-06-12 14:48:27 Prikshit Kumar
Is there a space after the dots or between the dashes?
2013-05-28 16:56:55 ওয়াসী (Wasi)
easy!
2013-04-13 12:50:58 divya gupta
sigsegv..

Last edit: 2013-04-13 18:09:11
2013-02-25 12:48:32 joud zouzou


Last edit: 2013-02-25 12:55:04
2012-12-28 10:12:17 Himanshu Sahu
got it in frist attempt!!!!!!!
AC!!!!!!!
this ques makes you better understand of gets,while,if-else and for loop??
try is its too simple...

Last edit: 2012-12-28 10:14:43
2012-12-20 05:39:55 Abhimanyu
got it !!!!! :)

Last edit: 2012-12-20 12:58:38
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.