C/C++の宿題を片付けます 117代目at TECH
C/C++の宿題を片付けます 117代目 - 暇つぶし2ch567:デフォルトの名無しさん
08/11/11 07:36:20
>>564
なんかへたくそでごめん。。
#include<stdio.h>
#define N 100
int n,cnt=0,c[N],b[N];
void solve(int a_top,int b_top,int c_top){
if(a_top>n && b_top==0){
int i;
for(i=0;i<n;i++)printf("%d",c[i]);
printf("\n"); cnt++;
}
if(a_top<=n){
b[b_top++] = a_top++;//a->b
solve(a_top,b_top,c_top);
b[--b_top] = --a_top;//b->a
}
if(b_top>0){
c[c_top++]=b[--b_top];//b->c
solve(a_top,b_top,c_top);
b[b_top++]=c[--c_top];//c->b
}
}
int main(){
printf("n:"); scanf("%d",&n);
if(n>0) solve(1,0,0);
printf("%d\n",cnt);
}


次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch