找回密码
 注册
搜索
热搜: 回贴
  • 前程无忧官网首页 有什么好的平台可以
  • 最新的销售平台 互联网营销的平台有哪
  • 制作网页的基本流程 网页制作和网页设
  • 【帝国CMS】输出带序号的列表(数字排
  • 网站建设公司 三一,中联,极东泵车的
  • 织梦 建站 织梦网站模版后台怎么更改
  • 云服务官网 哪些网站有免费的简历模板
  • 如何建网站要什么条件 建网站要用什么
  • 吉林市移动公司电话 吉林省退休人员网
  • 设计类毕业论文 网站设计与实现毕业论
查看: 974|回复: 9

有人会写算24的程序吗?

[复制链接]
发表于 2009-11-2 03:55:39 | 显示全部楼层 |阅读模式 IP:江苏扬州
这道题大致是这样的:任意输入四个10以内的数(0除外),计算24,要求输出计算式。
有兴趣的试试吧,很有意思。
有想看源码的说一声,我这里有C和C++的版本。
发表于 2009-11-2 03:55:43 | 显示全部楼层 IP:江苏扬州
暂时没有兴趣...
回复

使用道具 举报

发表于 2009-11-2 03:55:47 | 显示全部楼层 IP:江苏扬州
想法其实蛮简单的么,只要最后结果是24就成了,4个数据嘛,穷举也可以的拉,直接搜索咯,不过记得定义数组的时候用double哦,不然1,5,5,5就算不出来了
回复

使用道具 举报

发表于 2009-11-2 03:55:53 | 显示全部楼层 IP:江苏扬州
我想要啊,,QQ4160911
油箱:dlc_david@hotmail.com
回复

使用道具 举报

发表于 2009-11-2 03:56:00 | 显示全部楼层 IP:江苏扬州
--------------------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)


什么意思哦???
回复

使用道具 举报

发表于 2009-11-2 03:56:06 | 显示全部楼层 IP:江苏扬州
你最好另建一个工程将源码拷进去,直接用可能有问题
回复

使用道具 举报

发表于 2009-11-2 03:56:14 | 显示全部楼层 IP:江苏扬州
没时间琢磨 网上有很多吧

----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;
}
回复

使用道具 举报

发表于 2009-11-2 03:56:21 | 显示全部楼层 IP:江苏扬州
改成C++发来好不???
回复

使用道具 举报

发表于 2009-11-2 03:56:29 | 显示全部楼层 IP:江苏扬州
我要,呵,QQ:121260571EMAIL:1210lijian@sohu.com
回复

使用道具 举报

发表于 2009-11-2 03:56:38 | 显示全部楼层 IP:江苏扬州
有趣!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-9-30 01:39 , Processed in 0.185567 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表