Guest User

Untitled

a guest
Oct 18th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.98 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #define SIZE 100
  4.  
  5. void arraySort(int array[], int size) {
  6.     for ( int i = 1; i < size; i++ ) {
  7.         for ( int j = 1; j < size; j++ ) {
  8.             if ( array[j-1] > array[j] ) {
  9.                 int temp = array[j-1];
  10.                
  11.                 array[j-1] = array[j];
  12.                 array[j] = temp;
  13.             }
  14.         }
  15.     }
  16. }
  17.  
  18. int main() {
  19.     FILE *in = fopen("task.in", "r");
  20.     FILE *out = fopen("task.out", "w");
  21.     int array1[SIZE];
  22.     int array2[SIZE];
  23.     int counter = 0;
  24.     int size = 0;
  25.     char ch;
  26.    
  27.     for ( int i = 0; fscanf(in, "%c", &ch) == 1; i++ ) {
  28.         array1[i] = ch - 48;
  29.         array2[i] = ch - 48;
  30.         size += 1;
  31.     }
  32.    
  33.     arraySort(array1, size);
  34.    
  35.     for ( int i = 0; i < size; i++ ) {
  36.         if ( array1[i] != array2[i] ) {
  37.             counter += 1;
  38.         }
  39.     }
  40.    
  41.     fprintf(out, "%d\n", counter/2);
  42.    
  43.     fclose(in);
  44.     fclose(out);
  45.    
  46.     return 0;
  47. }
Add Comment
Please, Sign In to add comment