Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define SIZE 100
- void arraySort(int array[], int size) {
- for ( int i = 1; i < size; i++ ) {
- for ( int j = 1; j < size; j++ ) {
- if ( array[j-1] > array[j] ) {
- int temp = array[j-1];
- array[j-1] = array[j];
- array[j] = temp;
- }
- }
- }
- }
- int main() {
- FILE *in = fopen("task.in", "r");
- FILE *out = fopen("task.out", "w");
- int array1[SIZE];
- int array2[SIZE];
- int counter = 0;
- int size = 0;
- char ch;
- for ( int i = 0; fscanf(in, "%c", &ch) == 1; i++ ) {
- array1[i] = ch - 48;
- array2[i] = ch - 48;
- size += 1;
- }
- arraySort(array1, size);
- for ( int i = 0; i < size; i++ ) {
- if ( array1[i] != array2[i] ) {
- counter += 1;
- }
- }
- fprintf(out, "%d\n", counter/2);
- fclose(in);
- fclose(out);
- return 0;
- }
Add Comment
Please, Sign In to add comment