Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main(void) {
- char massiv[100];
- char n;
- char head_count = 0;
- char tail_count = 0;
- FILE *input_file = fopen("INPUT.TXT", "r");
- fscanf(input_file, "%hhi", &n);
- for (int i = 0; i < n; ++i) {
- fscanf(input_file, "%hhd", massiv + i);
- }
- fclose(input_file);
- for (int i = 0; i < n; ++i) {
- if (massiv[i] == 1) {
- head_count++;
- } else {
- tail_count++;
- }
- }
- FILE *output_file = fopen("OUTPUT.TXT", "w");
- if (head_count > tail_count) {
- fprintf(output_file, "%d", tail_count);
- } else {
- fprintf(output_file, "%d", head_count);
- }
- fclose(output_file);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement