~cpp #include <stdio.h> #include <string.h> void print_flap(char*, int); const int SIZE_BUFFER=100; void main() { while(1) { int number_cake=0; char cakes_size[SIZE_BUFFER]; printf("팬케이크의 크기를 순서대로 입력해주세요. (0은 종료 또는 입력완료)\n>>"); while (1) { scanf("%d",cakes_size+number_cake); if (0==cakes_size[number_cake]) break; ++number_cake; } if (0==number_cake) break; print_flap(cakes_size, number_cake); } } void print_flap(char* cakes_size, int number_cake) { printf ("결과 : "); for (register int i=number_cake-1; i>=0; --i) { int maximum=i; for (register int j=0; j<=i; ++j) { if (cakes_size[maximum]<cakes_size[j]) maximum=j; } if (maximum!=i) { if (maximum!=0) printf("%d ",number_cake-maximum); printf("%d ",number_cake-i); char temp[SIZE_BUFFER]; strcpy(temp,cakes_size); for (register j=0; j<=i; ++j) { if (j<=maximum) cakes_size[j-maximum+i]=temp[j]; else cakes_size[i-j]=temp[j]; } } } printf ("0 \n"); }