| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1060 人关注过本帖
标题:有人会写算24的程序吗?
只看楼主 加入收藏
zhaozhi406
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2005-12-25
收藏
 问题点数:0 回复次数:16 
有人会写算24的程序吗?
这道题大致是这样的:任意输入四个10以内的数(0除外),计算24,要求输出计算式。
有兴趣的试试吧,很有意思。
有想看源码的说一声,我这里有C和C++的版本。
搜索更多相关主题的帖子: 计算 
2005-12-25 22:39
冰☆snow
Rank: 1
等 级:新手上路
帖 子:40
专家分:0
注 册:2005-10-30
收藏
得分:0 
暂时没有兴趣...

耐人寻味~~!
2005-12-25 23:05
ElfDN
Rank: 4
等 级:贵宾
威 望:11
帖 子:291
专家分:0
注 册:2005-11-13
收藏
得分:0 
想法其实蛮简单的么,只要最后结果是24就成了,4个数据嘛,穷举也可以的拉,直接搜索咯,不过记得定义数组的时候用double哦,不然1,5,5,5就算不出来了

2005-12-25 23:56
dlcdavid
Rank: 3Rank: 3
来 自:成都
等 级:新手上路
威 望:6
帖 子:193
专家分:0
注 册:2005-12-23
收藏
得分:0 

我想要啊,,QQ4160911
油箱:dlc_david@hotmail.com


为了C++,我放弃了课本
为了高考,我又放弃了C++
现在而今眼目下,我能做什么?www.
2005-12-26 12:47
dlcdavid
Rank: 3Rank: 3
来 自:成都
等 级:新手上路
威 望:6
帖 子:193
专家分:0
注 册:2005-12-23
收藏
得分:0 

--------------------Configuration: Cpp1 - Win32 Debug--------------------
Compiling...
Cpp1.cpp
C:\Documents and Settings\user_child\桌面\算24的C程序\新建文件夹\Cpp1.cpp(175) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,std::basic_string<char,std::char_traits<char>,std::al
locator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,int>' : identifier was truncated to '255' characters in the debug information
C:\Documents and Settings\user_child\桌面\算24的C程序\新建文件夹\Cpp1.cpp(175) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,std::basic_string<char,std::char_traits<char>,std::allocato
r<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> > &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,int>' : identifier was truncated to '255' characters in the debug information
d:\download\vc98\include\vector(39) : warning C4786: 'std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >::vector<std::basic_string<
char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >' : identifier was truncated to '255' characters in the debug information
d:\download\vc98\include\vector(60) : warning C4786: 'std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >::~vector<std::basic_string
<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >' : identifier was truncated to '255' characters in the debug information
Linking...

Cpp1.exe - 0 error(s), 4 warning(s)


什么意思哦???


为了C++,我放弃了课本
为了高考,我又放弃了C++
现在而今眼目下,我能做什么?www.
2005-12-26 20:48
zhaozhi406
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2005-12-25
收藏
得分:0 

你最好另建一个工程将源码拷进去,直接用可能有问题


#include void main() { printf(\"回帖就感谢你!不回就鄙视你!\"); }
2005-12-26 21:41
unicorn
Rank: 4
等 级:贵宾
威 望:14
帖 子:1066
专家分:0
注 册:2005-10-25
收藏
得分:0 

没时间琢磨 网上有很多吧

----code quoted from google----

#include <stdio.h>
#include<math.h>
float a[4];
void cpl(int,int);
void count24();
float computer(float,float,int);
void main()
{
int i;
printf("Please input 4 number\n");
printf("The number should >0 and <14\n");
for(i=0;i<4;i++){
do{
scanf("%f",&a[i]);
if(a[i]<1||a[i]>13){
printf("The number is error\n");
}
}while(a[i]<1||a[i]>13);
}
cpl(0,4);
}
void cpl(int m, int n)
{
int i;
float t;
if (m<n-1) {
cpl(m+1, n);
for (i=m+1;i<n;i++) {
t=a[m]; a[m]=a[i]; a[i]=t;
cpl(m+1, n);
t=a[m]; a[m]=a[i]; a[i]=t;
}
} else
{
count24();
}
}

void count24()
{
int i,j,k;
float b[3];
char s[5]= "+-*/";
for(i=0;i<4;i++){
for(j=0;j<4;j++){
for(k=0;k<4;k++){
b[0]=computer(a[0],a[1],k);
b[1]=computer(b[0],a[2],j);
b[2]=computer(b[1],a[3],i);
if((abs(b[2]-24))<0.000001){
printf("%f= %f %c %f\n",b[0],a[0],s[k],a[1]);
printf("%f = %f %c %f\n",b[1],b[0],s[j],a[2]);
printf("%f = %f %c %f\n\n\n ",b[2],b[1],s[i],a[3]);
}
}
}
}
}


float computer(float m,float n,int op)
{
float temp;
switch(op){
case 0:
temp=m+n;
break;
case 1:
temp=m-n;
break;
case 2:
temp=m*n;
break;
case 3:
temp=m/n;
break;
}
return temp;
}


unicorn-h.spaces. ◇◆ sava-scratch.spaces.  noh enol ! pue pu!w hw u! shemle aq ll!m noh 
2005-12-26 21:47
dlcdavid
Rank: 3Rank: 3
来 自:成都
等 级:新手上路
威 望:6
帖 子:193
专家分:0
注 册:2005-12-23
收藏
得分:0 

改成C++发来好不???


为了C++,我放弃了课本
为了高考,我又放弃了C++
现在而今眼目下,我能做什么?www.
2005-12-26 23:15
lj3217734
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2006-3-1
收藏
得分:0 
我要哦

我要,呵,QQ:121260571EMAIL:1210lijian@sohu.com

2006-03-04 22:27
qingrenfeng
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-3-4
收藏
得分:0 

有趣!

2006-03-04 23:09
快速回复:有人会写算24的程序吗?
数据加载中...
 
   



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

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