ACM - Ancient China Mathematics

Description

It is really amazing that the great historian Dr.K has recently found that about 10 Million years ago, in the area where is now called China, lived an ancient people. They may be considered as the first intelligent creature existed on the earth.

As Dr.K's investigation advance, he found unbelievably that they even developed some so-called mathematics during their evolvement. Dr.K spent his half life to understand this ancient people's counting system. Finally he got to know that:

1�They use only 7 digits to represent numbers, and numbers are as follow:

| -> 1

|| -> 2

||| -> 3

|||| -> 4

||||| -> 5

|||||| -> 6

||||||| -> 7

It is a pity that they have not developed "0" before these people disappeared. 2�If a number is greater than 7, they use digit place just as we do today. Between each two digit places, there is a ",".

eg:

|||||,|| -> 42 (5x8+2)

|||,||,|||| -> 212 (3*64+2*8+4)

In order to further his study, Dr.K wants to know what the sequences found from stones mean in today's counting system. He turns to you for help, and smart as you are, you should help this great historian,should not you?

Input

The first line of standard input contains an integer N, the number of test cases. N lines followed.
In each line a sequence is given, it is guaranteed that the length of the sequence will not exceed 1024 characters and the outcome number will not be greater than 1000000.

Output

For each case you are to output a line giving the number in today's decimal 
counting system.

Sample Input

3
|||||,||
|||,||,||||
||,|,|,|,||||

Sample Output

42
212
8780

#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main()
{
    int t,i,j,ans,len,up,index;
    char ch[2100];
    scanf("%d",&t);
    getchar();
    while(t--)
    {
        up=1;
        gets(ch);
        len=strlen(ch);
        ans=0,index=0;
        for(i=len-1;i>=0;i--)
        {
            if(ch[i]!=',')index+=1;
            else
            {
                ans+=index*up;
                index=0;
                up*=8;
            }
        }
        ans+=index*up;
        printf("%d\n",ans);
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值