| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 737 人关注过本帖
标题:请教大家一个令我十分郁闷的编程题
只看楼主 加入收藏
kongyuehen
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2007-4-6
收藏
 问题点数:0 回复次数:8 
请教大家一个令我十分郁闷的编程题

题目:
第一题
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

搜索更多相关主题的帖子: first understand developed recently 
2007-04-28 23:07
kongyuehen
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2007-4-6
收藏
得分:0 
简言之:
输入3
|||||,||
|||,||,||||
||,|,|,|,||||
输出:
42
212
8780
2007-04-28 23:08
kongyuehen
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2007-4-6
收藏
得分:0 

为什么这段程序在i=1时是正确的,而在i>1时是错误的
#include <stdio.h>
#define MAX 54
void main()
{
char p;
int i,j,x;
float m=0,k=0;
char str[1024][MAX];
scanf("%d",&i);
printf("\n");
for(j=1;j<=i;j++)
{
scanf("%s",str[j]);
p=str[j][0];
while(p!='\0')
{
while(p!=',')
{k++;m++;
p=str[j][m];
if(p=='\0') goto loop;
}
m++;
k=k*8;
p=str[j][m];
}
loop: printf("%f\n",k);
}
}

如输入 1
     ||||,||||
输出 36 正确
而输入 2       输出
    ||||    4
    |,||    5
 错误
令我很郁闷,哪位大侠帮帮忙啊!!!!!

2007-04-28 23:13
I喜欢c
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:64
帖 子:1749
专家分:0
注 册:2007-3-2
收藏
得分:0 
以下是引用kongyuehen在2007-4-28 23:13:07的发言:

为什么这段程序在i=1时是正确的,而在i>1时是错误的
#include <stdio.h>
#define MAX 54
void main()
{
char p;
int i,j,x;
float m=0,k=0;
char str[1024][MAX];
scanf("%d",&i);
printf("\n");
for(j=1;j<=i;j++)
{
scanf("%s",str[j]);
m=0,k=0;
p=str[j][0];
while(p!='\0')
{
while(p!=',')
{k++;m++;
p=str[j][m];
if(p=='\0') goto loop;
}
m++;
k=k*8;
p=str[j][m];
}
loop: printf("%f\n",k);
}
}

如输入 1
     ||||,||||
输出 36 正确
而输入 2       输出
    ||||    4
    |,||    5
 错误
令我很郁闷,哪位大侠帮帮忙啊!!!!!


 我是指针,却丢失了目标地址!          我是循环,却缺少了结束条件!      我是函数,却没有人来调用!   
2007-04-28 23:26
kongyuehen
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2007-4-6
收藏
得分:0 

谢谢!实在是昨天头脑短路了!!!!!!谢谢

2007-04-29 12:47
编程怪兽
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2007-4-28
收藏
得分:0 

#include<stdio.h>
#define MAX 54
void main()
{
int i,m,k,sum=0;
char str[MAX][80];
int num;
printf("please input num:");
scanf("%d",&num);
for(i=0;i<num;i++)
{
scanf("%s",str[i]);
m=0;
k=0;
sum=0;
for(k=0;str[i][k]!='\0';k++)
{
while(str[i][k]!=',' && str[i][k]!='\0')
{
m++;
k++;
}
sum=sum*8+m;
m=0;
}
printf("%d\n",sum);
}
}


2007-05-07 21:16
lizhijie
Rank: 1
等 级:新手上路
帖 子:60
专家分:0
注 册:2007-4-28
收藏
得分:0 

我也写了这个程序,拿出来大家探讨一下:

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

#define DECI 8
#define ARRAY_SIZE 4

char *ancient_num[ARRAY_SIZE]={NULL};
int input_num=0;
int moden_num[ARRAY_SIZE];


void input();
void calculate();
void output();
int d(int decimal);

void main()
{
input();
calculate();
output();
}

void input()
{
int i;


printf("How many ancient numbers you want to input?\n");
scanf("%d",&input_num);

if(input_num>ARRAY_SIZE||input_num==0)
{
printf("You can put %d ancient numbers!\n",ARRAY_SIZE);
exit(0);
}
else
for(i=1;i<=input_num;i++)
{
printf("%d :",i);
scanf("%s",ancient_num[i-1]=(char*)malloc(80));
putchar('\n');
}

}

void calculate()
{
int i,j=0;
int len,decimal;
int stick; /*记录每一位上的”|“*/
char *rev; /*把字符串倒转*/
for(i=0;i<input_num;i++)
{
rev=(char*)malloc(80);
strrev(ancient_num[i]);
len=strlen(ancient_num[i]);
decimal=0;
stick=0;
for(j=0;j<len+1;j++)
{
if(ancient_num[i][j]=='|')
{
stick++;
}
else if(ancient_num[i][j]==',')
{
moden_num[i]+=(d(decimal)*stick);
stick=0;
decimal++;
}
else if(j==len)
{
moden_num[i]+=d(decimal)*stick;
}
}
free(ancient_num[i]);

}

}

int d(int decimal)
{
int i,deci=1;
if(decimal==0)
return 1;
else
for(i=0;i<decimal;i++)
deci*=DECI;
return deci;
}

void output()
{
int i;
printf("anser:\n");
for(i=0;i<input_num;i++)
{
printf("%d \n",moden_num[i]);
}
}


2007-05-07 21:31
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 

倚天照海花无数,流水高山心自知。
2007-05-07 21:39
爱以走远
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:52
帖 子:7542
专家分:21
注 册:2007-3-16
收藏
得分:0 

又是英语


   好好活着,因为我们会死很久!!!
2007-05-07 21:40
快速回复:请教大家一个令我十分郁闷的编程题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017667 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved