>  2009/05/27 (水) 22:04:18        [qwerty]
> > C++ だとこんな感じかしら(;´Д`)動くかどうかしらん
> > #include <stdio.h>
> > #include <stirng>
> > int tbl[]={1,5,3,2,8,4,9};
> > int ntbl = sizeof(tbl)/sizeof(int);
> > 
> > int func( std::string &str, int total, int *tbl, int ntbl)
> > {
> >   int total = 0;
> >   for(int i=0;i<ntbl-1; ++i){ 
> > 	std::string s = str+",",itoa(tbl[i]);
> > 	if( total+tbl[i]==9){
> > 	  printf("みつけたよ(%s)\n", s.c_str());
> > 	} else {
> > 	  func( s, total+tbl[i], tbl[i+1], ntbl-i);
> > 	}
> >   }
> >   return total;
> > }
> > int main(int argc, char *argv[])
> > {
> >  for(int i=0;i<ntbl;++i){
> >    std::string str;
> >    func(str, 0, tbl[i], ntbl);
> >    }
> >  }
> > return 0;
> > }
> やっぱり住人はすごいな(;´Д`)Perlで書いてください

http://krokus.sakura.ne.jp/topun/source/topun0259.jpg
いろいろ動くように直したよVC++用無料のでも動くだろうが(;´Д`)perlは簡便してください

#include "stdafx.h"
#include <stdlib.h>
#include <string>

int table[]={1,5,3,2,8,4,9};
int ntable = sizeof(table)/sizeof(int);


int func( std::string &str, int total, int *tbl, int ntbl)
{
  for(int i=0;i<ntbl-1; ++i){ 
	std::string s = str+",";
	char buf[0x10];
        _itoa_s(tbl[i],buf,0x10,10);
        s += buf;
	if( total+tbl[i]==9){
	  printf("みつけたよ(%s)\n", s.c_str());
	} else {
	  func( s, total+tbl[i], &tbl[i+1], (ntbl-(i+1) ) );
	}
  }
  return total;
}

int _tmain(int argc, _TCHAR* argv[])
{

   std::string str;
   func(str, 0, table, ntable);


 return 0;
}

参考:2009/05/27(水)21時35分33秒