(1). 5,5,5,1四个数字用+ - * / 怎样等于24,(题目简单20分)
(2). 用js或 vbs做个程序,用户随便输入四个数,(可用文本框)点击计算按纽得到等于24的计算方法。(其实不难,但我也没写,没时间,公司还有一些任务没做呢,先当是散分)(最少50分,看顶的人多不多,)
注。第二题一定要测试好才行,光写思路不算,哈哈,快来强分啊,
---------------------------------------------------------------
我来接分!~~
---------------------------------------------------------------
(5-1/5)*5
---------------------------------------------------------------
我刚要说,楼上都说了,来晚了, 啊
---------------------------------------------------------------
先接分
---------------------------------------------------------------
第一题:(5/1)×5+1-1-1=24
+ - * /都用上了
第二题:有时间再写
---------------------------------------------------------------
(5-1/5)*5
---------这个不对,没有用到+号。
我的才对:
(5/1)×5+1-1-1=24
---------------------------------------------------------------
再接分
---------------------------------------------------------------
接分!
---------------------------------------------------------------
就一种方法,没有方法了。
---------------------------------------------------------------
顶
---------------------------------------------------------------
up by I
---------------------------------------------------------------
楼主题目还是有点难度的,我看了看没想出来,再顶
---------------------------------------------------------------
转载[email protected]的算法(flash的)
1<html>
2<head>
3<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
4<title>无标题文档</title>
5</head>
6<body>
7<script language="JavaScript">
8a=5;
9b=5;
10c=5;
11d=1;
12var arr=new Array();
13arr[0]=new Array(a,b,c,d);
14arr[1]=new Array(a,b,d,c);
15arr[2]=new Array(a,c,b,d);
16arr[3]=new Array(a,c,d,b);
17arr[4]=new Array(a,d,b,c);
18arr[5]=new Array(a,d,c,b);
19arr[6]=new Array(b,a,c,d);
20arr[7]=new Array(b,a,d,c);
21arr[8]=new Array(b,c,a,d);
22arr[9]=new Array(b,c,d,a);
23arr[10]=new Array(b,d,a,c);
24arr[11]=new Array(b,d,c,a);
25arr[12]=new Array(c,a,b,d);
26arr[13]=new Array(c,a,d,b);
27arr[14]=new Array(c,b,a,d);
28arr[15]=new Array(c,b,d,a);
29arr[16]=new Array(c,d,a,b);
30arr[17]=new Array(c,d,b,a);
31arr[18]=new Array(d,a,b,c);
32arr[19]=new Array(d,a,c,b);
33arr[20]=new Array(d,b,a,c);
34arr[21]=new Array(d,b,c,a);
35arr[22]=new Array(d,c,a,b);
36arr[23]=new Array(d,c,b,a);
37var arr_b=new Array(4)
38var flag=false;
39for(i=0;i<24;i++){
40arr_b[0]=arr[i][0];
41arr_b[1]=arr[i][1];
42arr_b[2]=arr[i][2];
43arr_b[3]=arr[i][3];
44for(x=0;x<6;x++){
45for(y=0;y<6;y++){
46for(z=0;z<6;z++){
47if(cacu(cacu(cacu(arr_b[0],arr_b[1],x),arr_b[2],y),arr_b[3],z)==24){
48getResult(arr_b,x,y,z,1);
49flag=true;
50break;
51}
52if(cacu(cacu(arr_b[0],arr_b[1],x),cacu(arr_b[2],arr_b[3],z),y)==24){
53getResult(arr_b,x,y,z,2);
54flag=true;
55break;
56}
57}
58if(flag==true)
59break;
60}
61if(flag==true)
62break;
63}
64}
65if(flag==false)result="不能得到结果";
66
67
68function cacu(a,b,o){
69switch(o){
70case 0:
71return a+b;
72case 1:
73return a-b;
74case 2:
75return b-a;
76case 3:
77return a*b;
78case 4:
79return a/b;
80default:
81return b/a;
82}
83}
84function getOpt(o){
85switch(o){
86case 0:
87return "+";
88case 1:
89return "-";
90case 2:
91return "-";
92case 3:
93return "*";
94case 4:
95return "/";
96default:
97return "/";
98}
99}
100function getResult(a,x,y,z,flag){
101var str="";
102if(flag==1){
103if(x==2 ¦ ¦ x==5)
104str+=a[1]+getOpt(x)+a[0];
105else
106str+=a[0]+getOpt(x)+a[1];
107/////////////////
108if(y==2){
109if(x<3)
110str=a[2]+"-("+str+")";
111else
112str=a[2]+"-"+str;
113}else if(y==5){
114str=a[2]+"/("+str+")";
115}else{
116if(x<3 && y>2)
117str="("+str+")"+getOpt(y)+a[2];
118else
119str=str+getOpt(y)+a[2];
120}
121////////////////////////
122if(z==2){
123if(x<3 ¦ ¦ y<3)
124str=a[3]+"-"+str;
125}else if(z==5){
126str=a[3]+"/("+str+")";
127}else{
128if((x<3 ¦ ¦y<3) && z>2)
129str="("+str+")"+getOpt(z)+a[3];
130else
131str=str+getOpt(z)+a[3];
132}
133}else if(flag==2){
134if(x==2 ¦ ¦ x==5)
135str+=a[1]+getOpt(x)+a[0];
136else
137str+=a[0]+getOpt(x)+a[1];
138var str2="";
139if(z==2 ¦ ¦ z==5)
140str2+=a[3]+getOpt(z)+a[2];
141else
142str2+=a[2]+getOpt(z)+a[3];
143if(y>2){
144if(x<3)
145str="("+str+")";
146if(z<3)
147str2="("+str2+")";
148}
149if(y==2 ¦ ¦y==5)
150str=str2+getOpt(y)+str;
151else
152str=str+getOpt(y)+str2;
153}
154result=str+"=24";
155alert(result);
156}
157</script>
158<table border="0" cellpadding="0" cellspacing="0" width="100%">
159<tr>
160<td><span id="show1"></span>1111 </td>
161<td> </td>
162</tr>
163</table>
164</body>
165</html>
---------------------------------------------------------------
3551不能得到结果,呵呵
if(flag==false)result="不能得到结果";
加一下if(flag==false)alert("不能得到结果");
巧了,昨天刚看到的,原版是flash的http://www.flashempire.com/school/show_fla.php?id=407
---------------------------------------------------------------
:-),9行代码,日期转化汉字最短版,好象不能再短了
1<script language="vbs">
2Function D(x)
3if int(split(x,"-")(2)/10)=0 then D=D & F(split(x,"-")(2)) else _
4if split(x,"-")(2) mod 10 =0 then D=D & F(int(split(x,"-")(2)/10)) & "十" else _
5D=D & F(int(split(x,"-")(2)/10)) & "十" & F(split(x,"-")(2) mod 10)
6D=F(split(x,"-")(0)) & "年" & MonthName(split(x,"-")(1),True) & replace(D,"一十","十") & "日"
7end Function
8Function F(x)
9for i=1 to len(x)
10if mid(x,i,1)="0" then F=F & "零" else F=F & left(MonthName(mid(x,i,1),True),1)
11next
12end Function
13msgbox D(date)
14</script>