Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.65 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4.    
  5.     char massiv[100];
  6.     char n;
  7.     char head_count = 0;
  8.     char tail_count = 0;
  9.     FILE *input_file = fopen("INPUT.TXT", "r");
  10.    
  11.     fscanf(input_file, "%hhi", &n);
  12.    
  13.     for (int i = 0; i < n; ++i) {
  14.         fscanf(input_file, "%hhd", massiv + i);
  15.        
  16.     }
  17.    
  18.     fclose(input_file);
  19.    
  20.    
  21.     for (int i = 0; i < n; ++i) {
  22.         if (massiv[i] == 1) {
  23.             head_count++;
  24.         } else {
  25.             tail_count++;
  26.         }
  27.        
  28.     }
  29.    
  30.     FILE *output_file = fopen("OUTPUT.TXT", "w");
  31.    
  32.     if (head_count > tail_count) {
  33.         fprintf(output_file, "%d", tail_count);
  34.     } else {
  35.         fprintf(output_file, "%d", head_count);
  36.     }
  37.    
  38.     fclose(output_file);
  39.    
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement