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);
}
}
本文介绍了一种特殊的古代计数系统,并提供了一个程序用于将这种古老的计数方式转换为现代十进制计数系统。该程序能够解析由特定符号组成的序列,并将其转换为我们熟悉的数字。

被折叠的 条评论
为什么被折叠?



