1 solutions
-
0
C :
#include<stdio.h> #include<stdlib.h> #define N 10 int main() { int n; int count[N] = {0}; int count_n = 0; int i, j; int temp; int b; do { scanf("%d", &n); if(n == 0) break; int *a = (int *)malloc(n*sizeof(int)); for(i = 0; i < n; i++) { scanf("%d", &a[i]); } do { for(i = 0; i < n-1; i++) { if(a[i] > a[i+1]) { count[count_n]++; temp = a[i]; a[i] = a[i+1]; a[i+1] = temp; } } for(i = 0; i < n-1; i++) { if(a[i] < a[i+1]) { b = 1; continue; } else { b = 0; break; } } }while(!b); count_n++; }while(n); for(i = 0; i < count_n; i++) { printf("%d\n", count[i]); } return 0; }
- 1
Information
- ID
- 17259
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By