From kawada@po.jah.ne.jp Wed May 26 01:34:48 1999
Received: from wise19.mn.waseda.ac.jp (wise19.mn.waseda.ac.jp [133.9.4.137])
	by newton.kashi.info.waseda.ac.jp (8.8.8/3.7W) with ESMTP id BAA06733
	for <kashi@kashi.info.waseda.ac.jp>; Wed, 26 May 1999 01:34:46 +0900 (JST)
Received: from wise20.mn.waseda.ac.jp (wise20.mn.waseda.ac.jp [133.9.4.141]) by wise19.mn.waseda.ac.jp (8.9.1a/3.7W-19980811) with ESMTP id BAA07234 for <kashi@kashi.info.waseda.ac.jp>; Wed, 26 May 1999 01:23:53 +0900 (JST)
Received: from wise19.mn.waseda.ac.jp (wise19.mn.waseda.ac.jp [133.9.4.137]) by wise20.mn.waseda.ac.jp (8.9.1+3.0W/3.7W-19981111) with ESMTP id BAA16790 for <kashi@mn.waseda.ac.jp>; Wed, 26 May 1999 01:23:52 +0900 (JST)
Received: from po.jah.ne.jp (0@cosmo.jah.ne.jp [210.162.2.2]) by wise19.mn.waseda.ac.jp (8.9.1a/3.7W-19980811) with ESMTP id BAA07224 for <kashi@mn.waseda.ac.jp>; Wed, 26 May 1999 01:23:50 +0900 (JST)
Received: from DNS1 (pc127158.tokyo.jcom.ne.jp [210.234.127.158])
	by po.jah.ne.jp (8.8.8+3.0Wbeta13/3.6W-jahgw99040111) with SMTP id BAA28773
	for <kashi@mn.waseda.ac.jp>; Wed, 26 May 1999 01:23:46 +0900 (JST)
Message-ID: <001201bea6cb$1f552c00$9e7fead2@tokyo.jcom.ne.jp>
From: "Youhei Kawada" <kawada@po.jah.ne.jp>
To: =?iso-2022-jp?B?GyRCR3BMWhsoQiAbJEIybTFRGyhC?= <kashi@mn.waseda.ac.jp>
Subject: [JSJ] ticket2
Date: Wed, 26 May 1999 01:24:37 +0900
MIME-Version: 1.0
Content-Type: text/plain;
	charset="iso-2022-jp"
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 5.00.2014.211
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211
Status: OR

前回送ったプログラムに欠陥があったので送りなおします。


#include <iostream.h>
#include <fstream.h>

ofstream fout("c:\\output.txt",ios::out);
int num=0;
char *ope = "+-*/";


double calcu(int opera, double a, double b);
void print(int a, int b, int c, int d);
double print2(int p, double a, double b, int n);

void main(void){
 int i,j,k,l;
 for (i = 0; i <= 9; i++){for (j = i; j <= 9; j++){
  for (k = j; k <= 9; k++){for (l = k; l <= 9; l++){
   print(i,j,k,l); print(i,j,l,k); print(i,k,j,l); print(i,k,l,j); print(i,l,j,k); print(i,l,k,j);
   print(j,i,k,l); print(j,i,l,k); print(j,k,i,l); print(j,k,l,i); print(j,l,i,k); print(j,l,k,i);
   print(k,i,j,l); print(k,i,l,j); print(k,j,i,l); print(k,j,l,i); print(k,l,i,j); print(k,l,j,i);
   print(l,i,j,k); print(l,i,k,j); print(l,j,i,k); print(l,j,k,i); print(l,k,i,j); print(l,k,j,i);
 }}}}
}

void print(int a, int b, int c, int d){
 int p,q,r,m,n,o;
 double ans1,ans2,ans3;
 for (p = 0; p <= 3; p++){ for (q = 0; q <= 3; q++){ for (r = 0; r <= 3; r++){
  for (m = 0; m <= 1; m++){ for (n = 0; n <= 1; n++){ for (o = 0; o <= 1; o++){
   ans1 = print2(p,a,b,m);
   ans2 = print2(q,ans1,c,n);
   ans3 = print2(r,ans2,d,o);
   if (ans3 == 10){
    if(o%2){
     if(n%2){
      if(m%2){fout << "((" << a << ope[p] << b << ")" << ope[q] << c << ")" << ope[r] << d << " ";}
      else{fout << "((" << b << ope[p] << a << ")" << ope[q] << c << ")" << ope[r] << d << " ";}
     }
     else{
      if(m%2){fout << c << ope[q] << "(" << a << ope[p] << b << ")" << ope[r] << d << " ";}
      else{fout << c << ope[q] << "(" << b << ope[p] << a << ")" << ope[r] << d << " ";}
     }
    }
    else{
     if(n%2){
      if(m%2){fout << d << ope[r] << "((" << a << ope[p] << b << ")" << ope[q] << c << ")" <<  " ";}
      else{fout << d << ope[r] << "((" << b << ope[p] << a << ")" << ope[q] << c << ")" <<  " ";}
     }
     else{
      if(m%2){fout << d << ope[r] << "((" << c << ope[q] << "(" << a << ope[p] << b << "))" <<  " ";}
      else{fout << d << ope[r] << "((" << c << ope[q] << "(" << b << ope[p] << a << "))" <<  " ";}
     }
    }
    num++;
    if(num%7==0){fout << endl;}
   }
  }}}
 }}}

 for (p = 0; p <= 3; p++){ for (q = 0; q <= 3; q++){ for (r = 0; r <= 3; r++){
  for (m = 0; m <= 1; m++){ for (n = 0; n <= 1; n++){ for (o = 0; o <= 1; o++){
   ans1 = print2(p,a,b,m);
   ans2 = print2(q,c,d,n);
   ans3 = print2(r,ans1,ans2,o);
   if (ans3 == 10){
    if(o%2){
     if(n%2){
      if(m%2){fout << "(" << a << ope[p] << b << ")" << ope[r] << "(" << c << ope[q] << d << ")" << " ";}
      else{fout << "(" << b << ope[p] << a << ")" << ope[r] << "(" << c << ope[q] << d << ")" << " ";}
     }
     else{
      if(m%2){fout << "(" << a << ope[p] << b << ")" << ope[r] << "(" << d << ope[q] << c << ")" << " ";}
      else{fout << "(" << b << ope[p] << a << ")" << ope[r] << "(" << d << ope[q] << c << ")" << " ";}
     }
    }
    else{
     if(n%2){
      if(m%2){fout << "(" << c << ope[p] << d << ")" << ope[r] << "(" << a << ope[q] << b << ")" << " ";}
      else{fout << "(" << c << ope[p] << d << ")" << ope[r] << "(" << b << ope[q] << a << ")" << " ";}
     }
     else{
      if(m%2){fout << "(" << c << ope[p] << d << ")" << ope[r] << "(" << a << ope[q] << b << ")" << " ";}
      else{fout << "(" << d << ope[p] << c << ")" << ope[r] << "(" << b << ope[q] << a << ")" << " ";}
     }
    }
    num++;
    if(num%7==0){fout << endl;}
   }
  }}}
 }}}
}

double print2(int p, double a, double b, int n){
 if(n%2) { return(calcu(p, a, b)); }
 else { return(calcu(p, b, a)); }
}

double calcu(int opera, double a, double b){
 switch (opera){
 case  0: return(a + b); break;
 case  1: return(a - b); break;
 case  2: return(a * b); break;
 default: return(a / b); break;
 }
}

----
早稲田大学理工学部情報学科3年
G97P029-2  川田 洋平
kawada@po.jah.ne.jp
g97p0292@mn.waseda.ac.jp