Alien Numerals


Submit solution

Points: 10
Time limit: 1.0s
Memory limit: 1000K

Author:
Problem type
Allowed languages
C

An alien species has made contact with you. You have even struck up a deal with them for purchasing superior technology from them. However, to negotiate payment you need to translate their numerals to your number system.

Their number systems use 7 numerals/symbols !, @, #, $, ^, &, and * with face values 0 to 6 respectively.

You are required to read values in their number system and convert it to decimal number system. That is, number system to the base 10 consisting of numerals/symbols 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9 with corresponding face values respectively.

Input Format:

First line of input will be sequence of characters.

CONDITIONS

Sequence will only contain characters ! @ # $ ^ & and *

Sequence will not contain any other symbols such as hyphen, comma, space or floating point.

Maximum length of sequence is 16.

The sequence will be terminated by either newline or whitespace character.

Output Format:

Exactly 1 integer value followed by newline

In case of any constraint violation the program should terminate printing a newline.

Sample Input 1

&^

Sample Output 1

39

Sample Input 2

&@!@!!^

Sample Output 2

605399

Sample Input 3

^$**##!

Sample Output 3

537593

Sample Input 4

****************

Sample Output 4

33232930569600

Sample Input 5

-@!&$**.^^

Sample Output 5

 

Sample Input 6

@#$^&!@#$^&!@#$^&*!

Sample Output 6

 

Example 1

@#

The number can be interpreted as:

face value of @ x base value of number system ^ index value of @ +

face value of # x base value of number system ^ index value of #

Face value of @ is 1; Index of @ is 1; Base of number system is 7

Face value of # is 2; Index of # is 0; Base of number system is 7

1x7^1 + 2x7^0 => 7 + 2 => 9

The decimal equivalent of @# or (12) to the base 7 is 9.

Example 2

****************

The number can be interpreted as:

Face value of * is 6;

6x7^15 + 6x7^14 + 6x7^13 + 6x7^12 + 6x7^11 + 6x7^10 + 6x7^9 + 6x7^8 + 6x7^7 + 6x7^6 + 6x7^5 + 6x7^4 + 6x7^3 + 6x7^2 + 6x7^1 + 6x7^0

=> 28485369059658 + 4069338437094 + 581334062442 + 83047723206 + 11863960458 + 1694851494 + 242121642 + 34588806 + 4941258 + 705894 + 100842 + 14406 + 2058 + 294 + 42 + 6

=> 33232930569600

The decimal equivalent of (****************) or (6666666666666666) to the base 7 is 33232930569600.

Programming Requirements:

  • Static Arrays

TAGS: C Programming, Static Arrays


Comments

There are no comments at the moment.