Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> How to make 9 8 7 6 =24
LuciferStar
post Aug 10 2004, 07:44 AM
Post #1


Advanced Member
*******

Group: Members
Posts: 114
Joined: 9-August 04
From: Suzhou Jiangsu China
Member No.: 743



CODE
#include "stdio.h"
#include "process.h"
int fun0(int x,int y){return (x+y);}
int fun1(int x,int y){return (x-y);}
int fun2(int x,int y){return (x*y);}
int fun3(int x,int y){return (x/y);}
int (*assign[4])(int x,int y);
void assign_function(void)
{
assign[0]=fun0;
assign[1]=fun1;
assign[2]=fun2;
assign[3]=fun3;
}
//const int data[4]={9,8,7,1};
int data[4]={9,8,7,1};
const int fetch[24][4]={
{3,2,1,0},{0,3,2,1},{1,0,3,2},{2,1,0,3},
{3,1,2,0},{0,3,1,2},{2,0,3,1},{1,2,0,3},
{3,0,1,2},{2,3,0,1},{1,2,3,0},{0,1,2,3},
{3,2,0,1},{1,3,2,0},{0,1,3,2},{2,0,1,3},
{3,0,1,2},{1,3,0,2},{2,1,3,0},{0,2,1,3},
{3,1,0,2},{2,3,1,0},{0,2,3,1},{1,0,2,3}};
int calculator[4];
void result(int x,int y,int r,int n)
{
int a[4],b[4];
char  fomular[20],o[4]={'+','-','*','/'};
for(int i=0;i<4;i++)
{
a[i]=fetch[x][i];
b[i]=data[fetch[y][i]];//printf("a[%d]:%d  b[%d]:%d  o[%d]:%c  o[a[%d]]:%c\n",i,a[i],i,b[i],i,o[i],i,o[a[i]]);
}
if((a[0]==0||a[0]==1)&&(a[1]==2||a[1]==3))
  sprintf(fomular,"Method %d:  (%d%c%d)%c%d%c%d=%d\n",n,b[0],o[a[0]],b[1],o[a[1]],b[2],o[a[2]],b[3],r);
else if((a[0]==2||a[0]==3)&&(a[3]!=2||a[3]!=3))
  sprintf(fomular,"Method %d:  %d%c%d%c%d%c%d=%d\n",n,b[0],o[a[0]],b[1],o[a[1]],b[2],o[a[2]],b[3],r);
else sprintf(fomular,"Method %d:  (%d%c%d%c%d)%c%d=%d\n",n,b[0],o[a[0]],b[1],o[a[1]],b[2],o[a[2]],b[3],r);
//printf("\tResult:\n");
printf("\t%s",fomular);

}

void main(void)
{  int r=24;
  //int temp;
  int n=0;
assign_function();
printf("\t\tAchieve 24 point\n\n\tBy Lucifer Star\n\tSingle Studio\n\t\tEMAIL:LetMeGetOne@hotmail.com\n\n");
printf("*****************************************\n");
printf("\tPlease input 1st number:");
scanf("%d",&data[0]);
printf("\tPlease input 2nd number:");
scanf("%d",&data[1]);
printf("\tPlease input 3rd number:");
scanf("%d",&data[2]);
printf("\tPlease input 4th number:");
scanf("%d",&data[3]);
printf("\tWhat do you want to achieve(default:24):");
scanf("%d",&r);
//scanf("%d",&temp);
//temp=getch();
//if(temp!=0x0d) r=temp;

printf("\n     ***********************************\n");
if(data[0]==0||data[1]==0||data[2]==0||data[3]==0) {printf("The 4 numbers shouldn't be 0!");exit(0);}
for(int ii=0;ii<24;ii++)
{
  for(int i=0;i<24;i++)
  {
    int z=0;
    for(int j=0;j<4;j++)
    {
 calculator[j]=data[fetch[i][j]];
    }
    for(int k=0;k<3;k++)
    {
 if(k==0)
 {
    if(calculator[0]%calculator[1]!=0&&fetch[ii][0]==3)
       {z=0;break;}
    else z=assign[fetch[ii][k]](calculator[k],calculator[k+1]);
 }
 else
 {  if(fetch[ii][k]==3)
      if(calculator[k+1]==0||z==0||(z%calculator[k+1])!=0)
     {z=0;break;}
    z=assign[fetch[ii][k]](z,calculator[k+1]);
 }
    }
    if(z==r)
    {    n++;result(ii,i,r,n);   }
   }
}
printf("\n******************************************\n");
if(n==0) printf("Sorry,it's unable to do so!");
else printf("Thanks for using my software!");
}
Go to the top of the page
 
+Quote Post
neeki4444
post Sep 1 2004, 02:18 PM
Post #2


Newbie [Level 2]
**

Group: Members
Posts: 38
Joined: 31-August 04
Member No.: 967



don't use printf use cout its more secure. Using print may lead to bufferover flows and hackers can easily gain control of the computer by injecting some extra code themselves
Go to the top of the page
 
+Quote Post
OpaQue
post Sep 1 2004, 06:07 PM
Post #3


Administrator
Group Icon

Group: Admin
Posts: 1,479
Joined: 11-June 04
From: Somewhere in Time & Space.
Member No.: 1



I prefer printf because it is fast and gives more power. Formatting can be done easily. Besides, looking at the above program, since iostream.h is not included, cout cannot be included. its a pure c program.
Go to the top of the page
 
+Quote Post
LuciferStar
post Sep 3 2004, 11:40 AM
Post #4


Advanced Member
*******

Group: Members
Posts: 114
Joined: 9-August 04
From: Suzhou Jiangsu China
Member No.: 743



I've learned C for more than 5 years,
and I found it's hard for me to learn C++,though I can understand it.

CLASS is hard to me.

the output of cout is variable,uncontrolable,I think.
Go to the top of the page
 
+Quote Post
goranche
post Sep 24 2004, 01:53 PM
Post #5


Newbie
*

Group: Members
Posts: 7
Joined: 24-September 04
Member No.: 1,253



don't be scared with c++. Every thing that you are doing in C++ you CAN do in C but in more complex way...
classes are invented to make peoples unsecured but it's not so hard...

To all of you...
I'm from Serbia. I'm new here on Trap17. I'm pleased to be with you folks, but you must forgive me on my "bad" english.. wink.gif
Go to the top of the page
 
+Quote Post
LuciferStar
post Sep 25 2004, 11:48 AM
Post #6


Advanced Member
*******

Group: Members
Posts: 114
Joined: 9-August 04
From: Suzhou Jiangsu China
Member No.: 743



QUOTE(goranche @ Sep 24 2004, 01:53 PM)
don't be scared with c++. Every thing that you are doing in C++ you CAN do in C but in more complex way...
classes are invented to make peoples unsecured but it's not so hard...

To all of you...
I'm from Serbia. I'm new here on Trap17. I'm pleased to be with you folks, but you must forgive me on my "bad" english..  wink.gif

I 'm from China. wink.gif
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Make Money Online!(22)
  2. Make Your Own Mmog(7)
  3. How To Make A Counter Strike 1.6 Dedicated Server(18)
  4. Signature Tutorial(27)
  5. French Kiss Or Make Out?(6)
  6. What Are The Ways To Make Your Poems Spread To The Audience?(2)
  7. Best Way To Make Money From Your Website?(16)
  8. File Sharing Hosts!(11)
  9. Cannot Make Another Application Even Though Last Was Denied(2)
  10. How Do I Make A Website(21)
  11. Javascript Slideshow Tutorial(4)
  12. How To Make Money Online(0)
  13. Runescape Private Server(76)
  14. How To Make Money Online At Home(7)
  15. That Its Hard To Make It Team(1)
  1. Does Anyone Know How To Make Exe Files(19)
  2. What Kind Of Car Do You Have?(30)
  3. Make Your Exercise Injury-free(0)
  4. How Would You Make An Apple Netbook?(1)
  5. Is It Really Possible To Make Any Money Online?(28)
  6. Make A Folder Named Con(7)
  7. Help Creating A Profile Website(14)
  8. Free 10 Day Affiliate Masters E-course(0)
  9. Martial Science(1)
  10. Budding Java Game Developers?(10)
  11. I Want To Make An Mmorpg(4)
  12. Best Ways To Make Money In Runescape(13)
  13. Try To Make Con Folder In Microsoft Os(9)
  14. how to make a pc server?(30)
  15. How To Make An Item Scroll With You On The Page.(10)


 



- Lo-Fi Version Time is now: 12th October 2008 - 07:30 AM