“現在的程序員怎麼越來越素質低下了撒,經常在BBS上看到我不要解決方法,我只要源代碼,TNND,
方法都給你了,實現還要人寫阿,說得不好聽得話,你娶個老婆不會gan,你爸爸告訴你方法,你怎麼
就不讓你爸爸替你gan呢,真是垃圾,別人時間不值錢阿,憑什麼讓你不勞而獲?”
下面在www.delphibbs.com上看到的一個簡單問題的貼子,發貼人就是這類人,
URL:http://www.delphibbs.com/delphibbs/dispq.asp?lid=3524495
問題:移動公司的一道簡單面試題,居然很多大學生做不出 ( 積分:1, 回覆:34, 閱讀:1032 )
分類:數據庫-文件型 ( 版主:hbezwwl, bubble )
來自:gigi788, 時間:2006-8-3 16:29:00, ID:3524495
以下爲問題描述和解題方法:
問題:A和B,A說:我是你現在這個年齡的時候啊,你才4歲。B說:等我到了你現在這個年齡呀,你都67歲了。那A和B現在分別是幾歲?
假定
A: x歲
B: y歲
A和B相差:z歲
那麼
x-y=z
y-4=z
67-x=z
從而
x-y=y-4 =>x=2y-4 =>x=2*(71-x)-4=138-2x=>x=138/3=46
67-x=y-4 =>y=71-x =>y=71-46=25
1、C#實現代碼:
private void button1_Click(object sender, EventArgs e)
{
int x;
int y;
int z;
for (x = 1; x <= 67; x++)
{
for (y = 1; y <= 67; y++)
{
z = x - y;
if ((67 - x) == z && (y - 4) == z)
{
MessageBox.Show("A年齡:" + x.ToString() + " 歲,B年齡:" + y.ToString() + " 歲");
}
}
}
}
2、Delphi實現:
procedure TForm3.Button1Click(Sender: TObject);
var
x:integer;
y:integer;
z:integer;
begin
for x:=1 to 67 do
begin
for y:=1 to 67 do
begin
z:=x-y;
if(((67-x)=z)and((y-4)=z)) then
ShowMessage('A年齡:' + IntToStr(x) + ' 歲,B年齡:' + IntToStr(y) + ' 歲');
end;
end;
end;
3、JavaScript實現:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>計算年齡</title>
</head>
<script langguage="javascript" >
function calculate_Age()
{ var x;
var y;
var z;
for (x = 1; x <= 67; x++)
{
for (y = 1; y <= 67; y++)
{
z = x - y;
if ((67 - x) == z && (y - 4) == z)
{
alert("A年齡:" + x + " 歲,B年齡:" + y + " 歲");
}
}
}
}
</script>
<body>
<input type="button" name="Submit" value="計算" οnclick="calculate_Age();" />
</body>
</html>
4、VBScript實現:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>計算年齡</title>
</head>
<body>
<input type="button" name="button1" value="計算">
<script language="vbscript">
<!--
sub button1_onclick
dim x
dim y
dim z
for x = 1 to 67
for y = 1 to 67
z = x - y
if (((67 - x) = z) and ((y - 4) =z)) then
MsgBox("A年齡:" & CStr(x) & " 歲,B年齡:" & CStr(y) & " 歲")
end if
next
next
end sub
-->
</script>
</body>
</html>
5、PHP實現:
<html>
<head>
<title>計算年齡</title>
</head>
<body>
<?php
for ($x = 1; $x <= 67; $x++)
{
for ($y = 1; $y <= 67; $y++)
{
$z=$-$y;
if ((67 - $x) == $z && ($y - 4) == $z)
{
echo "A年齡:" + strval($x) + " 歲,B年齡:" + strval($y) + " 歲";
}
}
}
?>
</body>
</html>
6、其他語言代碼,你想要還可以給你實現一下,哼哼。。。