请高手指点迷津!急!在线恭候...

燕尾鱼 2007-04-28 02:30:48
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
...全文
321 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
D_BOY_JQ 2007-04-28
  • 打赏
  • 举报
回复
我不是高手:)
#include <iostream>
#include <string>
#include <queue>
#include <math.h>

using namespace std;

int main(int, char*[])
{
int nLineCount;
char input[1024];
cout<<"input:\n";
cin>>nLineCount;
queue<string> v;

for (int i = 0; i < nLineCount; ++i)
{
cin>>input;
int start = 0;
int result = 0;
int j;

for (j = 0; input[j] != 0; ++j)
{
if (input[j] == ',')
{
v.push(string(input + start, input + j));
start = j + 1;
}
}

if (j > start)
{
v.push(string(input + start, input + j));
}

while(v.size() > 0)
{
result += (v.front().size() * pow(8.f, (int)v.size() - 1));
v.pop();
}
cout<<result<<endl;
}

return 0;
}
燕尾鱼 2007-04-28
  • 打赏
  • 举报
回复
要求是一次性出结果

输入格式:
3
|||||,||
|||,||,||||
||,|,|,|,||||

输出格式:
42
212
8780
哥(星辰)麻烦你再帮我想想吧
谢谢了 我挺着急的
dai_weitao 2007-04-28
  • 打赏
  • 举报
回复
这个很简单啊.
把输入存入char *buf[BUFFSIZE]中, 用for循环从头至尾分离buf的内容.
剩下的就是计算问题了.
jixingzhong 2007-04-28
  • 打赏
  • 举报
回复
如果需要做 输入正确性 校验,
使用 string 的 find_first_not_of 方法即可。
jixingzhong 2007-04-28
  • 打赏
  • 举报
回复
#include <cmath>
#include <string>
#include <iostream>
#include <cstdlib>

int main()
{
int i, n;
cout<<"请输入行数: ";
cin>>n;

string line, tmp;
int num, index, power;
for(i=1; i<n+1; i++)
{
num=0, power=0, index=0;
cout<<"请输入第 "<<i<<" 行: ";
cin>>line;

index = line.find(',', 0);
while(index != string::npos)
{
power++;
index = line.find(',', index+1);
}

tmp = line;
while(power>0)
{
index = tmp.find(',', 0);
num += (index)*pow(8.0, power);
tmp = tmp.substr(index+1);
power --;
}
num += tmp.length();
cout<<line<<" ~ "<<num<<endl;
}
system("pause");
return 0;
}
jixingzhong 2007-04-28
  • 打赏
  • 举报
回复
不做输入的正确性校验,
(即假设用户输入都是符合 输入数据标准的)
参考代码如下:
lidongri 2007-04-28
  • 打赏
  • 举报
回复
用中文把

64,649

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧