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

燕尾鱼 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
...全文
331 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用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
  • 打赏
  • 举报
回复
用中文把
在CSDN上转悠经常看到有网友寻求PowerDesigner相关资料的帖子,Baidu,Google上找找还真很少;同时也有不少网友发来Email询问相关PowerDesigner问题或索要相关资料的,故下定决心制作本文档。折腾二十多天,终于输出了现在的文档,其中绝大部分内容都是依照PowerDesigner自带的帮助文档翻译过来,乐意啃英文的朋友最好还是看其”原汁”教程,同时本文档仅用于帮助分析设计人员更快熟悉掌握PowerDesigner的使用方法,不包含分析设计方面的理论,所以要作好系统的分析设计工作还是需要用户深厚的项目实践功底。

起初想尽量按照PowerDesigner自带帮助文档完整地进行,尝试了一上午的工作之后这种方案马上就被我否决,原因有二:1.内容太多,工作量太多。2.原帮助文档特别周全,个人觉得可以在内容上作很大程度的压缩。姑决定按原帮助文档写,同时加入自己目前正在做的技术论坛分析设计过程以便于理解。

对本文档内容的几点说明:

1. 本文档只包括PowerDesigner部分内容(RQM,Report,CDM,PDM),内容不够全面。

2. 内容尽量简略,一些相同或类似操作过程尽量不再重复。

3. 部分术语参考了飞思科技产品研发中心监制电子工业出版社的《PowerDesigner数据库系统分析设计与应用》。

4. 暂时没有包含OOM,XML,BPM,ILM等模型内容,我将会在后期陆续更新。

版本说明:我使用的是PowerDesigner Trial 11英文版,因此文档中一些菜单,按钮名称也用英文写出(因当心自己译出的名称和中文版上的名称不一致而造成理解不便),若是给使用中文版的朋友带来不便,我在这说声”抱歉”了!同时由于各版本不同部分操作可能会有所区别。

这里要感谢在我进行翻译工作期间给我发送Email关注的网友,感谢一直支持我的朋友们!由于第一次做翻译工作,限于水平有限,文档中肯定存在很多不足和错误之处,衷心欢迎各位网友指点迷津,期望得到您的指导!



Email:dingchungao@gmail.com dingchungao@126.com

QQ:330982401

Blog:http:\\feiren1421.cnblogs.com





Slash

2006.8.31

65,199

社区成员

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

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