-4

给定一个周期数列示例 X=3

x=3 的定期序列必须如下所示

1 1 1
1 1 2
1 1 3
1 2 1
1 2 2
1 2 3
1 3 1
1 3 2
1 3 3
2 1 1
2 1 2
2 1 3
2 2 1
2 2 2
2 2 3
2 3 1
2 3 2
2 3 3 
3 1 1 
3 1 2
3 1 3
3 2 1
3 2 2
3 2 3
3 3 1
3 3 2
3 3 3

想要:用 C 编写一个程序来打印这个系列并给出:假设 x 的最大值可以是 10

我试图从想法开始..但都失败了..请帮助。谢谢 :)

4

2 回答 2

1
def yourFunction(n, x):
    recursiveFunction(n, x, 0, [0]*n)

def recursiveFunction(depth, breadth, currentDepth, indexes):
    if currentDepth >= depth:
        print indexes
    else:
        for indexes[currentDepth] in range(0, breadth):
             recursiveFunction(depth, breadth, currentDepth + 1, indexes)
于 2013-06-20T20:15:04.483 回答
0
#include<stdio.h>
#include<stdlib.h>

int printSeries(int list[], int max, int level){
    if(level == max){
        int i;
        for(i=0;i<max;++i)
            printf("%d ", list[i]);
        printf("\n");
        return 1;
    }
    while(list[level]<=max){
        list[level]+=printSeries(list, max, level+1);
    }
    list[level] = 1;

    return 1;
}

void printSeriesStart(int x){
    int i, *list = malloc(x*sizeof(int));

    for(i=0;i<x;++i){
        list[i]=1;
    }
    printSeries(list, x, 0);
    free(list);
}

int main(void){
    int X = 3;
    printSeriesStart(X);
    return 0;
}
于 2013-06-20T22:30:18.073 回答