郁闷
View Code
#include<stdio.h> #include<stdlib.h> int cmp(const void *a,const void *b) { return *(int *)a - *(int *)b; } int main() { int a[102] = {0}, b[102], top = 0; int i, j, k, flag, t; char ch; while((ch = getchar()) != EOF) { if(ch == ' ') { top++; } else if (ch >='1' && ch <= '9') { if(a[top] != 0) { a[top] = a[top]*10+ch-'0'; } else a[top] = ch-'0'; b[top] = a[top]; } else { for(i = 0;i < top; i++) printf("%d ",a[i]); printf("%d\n",a[top]); top++; qsort(b,top,sizeof(b[0]),cmp); flag = top-1; for(i = top-1;i >= 0; i--) { if(a[i] != b[i]) { for(j = 0;j <= i; j++) if(a[j] == b[i]) break; if(j != 0) { printf("%d ",top-j); for(k = 0;k < j; k++,j--) { t = a[k]; a[k] = a[j]; a[j] = t; } printf("%d ",top-i); for(k = 0;k <= i/2; k++) { t = a[k]; a[k] = a[i-k]; a[i-k] = t; } } else { printf("%d ",top-i); for(k = 0;k <= i/2; k++) { t = a[k]; a[k] = a[i-k]; a[i-k] = t; } } } } printf("0\n"); top = 0; memset(a,0,sizeof(a)); } } return 0; }