#include <stdio.h>
#include <malloc.h>
//#define FIN "submultimi.in"
//#define FOUT "submultimi.out"
typedef struct node {
int info;
struct node *next;
} Stack;
void push(Stack**head, int value){
Stack
*q
=(Stack
*)malloc(sizeof(Stack
)); q->info = value;
q->next = *head;
*head = q;
}
int isEmpty(Stack*head) {
if(head==NULL) return 1;
return 0;
}
void pop(Stack**head) {
Stack*q;
q = *head;
if(isEmpty(*head)) return;
(*head) = (*head)->next;
}
int top(Stack**head){
if(!isEmpty(*head))
return (*head)->info;
return -1;
}
void topPlusPlus(Stack**head) {
(*head)->info = (*head)->info + 1;
}
void write(Stack*head) {
int arr[100], k = 0;
while(head){
arr[k++] = head->info;
head = head->next;
}
for(int i
= k
-1; i
>= 0; i
--) printf("%d ", arr
[i
]); }
int main(int argc, char const *argv[]) {
Stack*head=NULL;
int n;
//freopen(FIN, "r",stdin);
//freopen(FOUT,"w",stdout);
push(&head,1);
while(!isEmpty(head)) {
write(head);
if(top(&head) < n) push(&head,top(&head)+1);
else {
pop(&head);
if(!isEmpty(head)) topPlusPlus(&head);
}
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxtYWxsb2MuaD4KLy8jZGVmaW5lIEZJTiAic3VibXVsdGltaS5pbiIKLy8jZGVmaW5lIEZPVVQgInN1Ym11bHRpbWkub3V0IgoKCnR5cGVkZWYgc3RydWN0IG5vZGUgewogICAgaW50IGluZm87CiAgICBzdHJ1Y3Qgbm9kZSAqbmV4dDsKfSBTdGFjazsKCnZvaWQgcHVzaChTdGFjayoqaGVhZCwgaW50IHZhbHVlKXsKICAgICBTdGFjaypxPShTdGFjayopbWFsbG9jKHNpemVvZihTdGFjaykpOwogICAgIHEtPmluZm8gPSB2YWx1ZTsKICAgICBxLT5uZXh0ID0gKmhlYWQ7CiAgICAgKmhlYWQgPSBxOwp9CgppbnQgaXNFbXB0eShTdGFjaypoZWFkKSB7CiAgaWYoaGVhZD09TlVMTCkgcmV0dXJuIDE7CiAgcmV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