观海听涛BBS's Archiver

wangruihit 发表于 2008-4-14 18:49

华为面试题

假设一年365天,光速为350万千米/秒,写一个函数打印光一年走过多少米?

蓝月鸟 发表于 2008-4-14 18:54

又一个拿数组当数字的
[em26]

爱因 发表于 2008-4-14 19:26

又是华为的~~~[em07]

zhponly 发表于 2008-4-14 19:32

[code]//usage:distance of a lightyear
//author:zhponly
//date:20080414
//edit:none
//edition:none
//vc++6.0+windows xp
#include<iostream>
void PrintDistanceOfL(void);
using namespace std;
int main(void)
{
PrintDistanceOfL();
return 0;
}
void PrintDistanceOfL(void)
{
long unsigned int Result;    //result
unsigned int DayOfYear=365;   
unsigned int SecondsOfDay=864;    //secondsofday=864*1 00
unsigned int SpeedOfL=35;         //speedofl=35*1 0000 0000m
Result=DayOfYear*SecondsOfDay*SpeedOfL;
cout<<Result;             //less of 00 0000 0000
for(int i=0;i<10;i++)
         cout<<0;             // 00 0000 0000
cout<<endl;              //change line
}[/code]

zhponly 发表于 2008-4-14 19:33

貌似光速不是一秒35吧..............[em30]

凡星 发表于 2008-4-16 10:23

倒不是特别特别难 就是题目太变态了 。。。

这样的题我就做不出来。。

wangruihit 发表于 2008-4-16 19:02

ANSWER:可以只计算365*24*36*35保存为字符串后面在接几个0

爱因 发表于 2008-4-16 19:14

才发现 光速变了

wangruihit 发表于 2008-4-16 19:20

[quote]原帖由 [i]爱因[/i] 于 2008-4-16 19:14 发表 [url=http://bbs.ghtt.net/redirect.php?goto=findpost&pid=1191733&ptid=101554][img]http://bbs.ghtt.net/images/common/back.gif[/img][/url]
才发现 光速变了 [/quot



哈哈,什么都会变的,不要跟不上时代。

梦想舞台 发表于 2008-4-18 14:45

华为总是这么bt

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.