viewing paste Unknown #35652 | Python

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
#include <stdio.h>
 
int main()
{
    FILE *input = fopen("input.txt", "r");
    FILE *output = fopen("output.txt", "w");
    int n, k;
    fscanf(input, "%i %i\n", &n, &k);
    printf("%d", k);
    int array[n];
    int buffer;
    int i = 0;
    while(fscanf(input, "%i", &buffer))
    {
        array[i] = buffer;
        i++;
    }
    fclose(input);
    double maxNEDOVOLEN = 100000000;
    int floorOfNedovolen = 1;
    for(int floor = 2; floor < k; floor++)
    {
        int NEDOVOLEN = 0;
        for(int i = 0; i < n; i++)
        {
            int neededFloor = array[i];
            printf("%d", neededFloor);
            if(neededFloor < floor)
            {
                NEDOVOLEN += floor - neededFloor;
            }
            else
            {
                NEDOVOLEN += (neededFloor - floor) * 2;
            }
        }
        printf("%d", NEDOVOLEN);
        if(NEDOVOLEN < maxNEDOVOLEN)
        {
            maxNEDOVOLEN = NEDOVOLEN;
            floorOfNedovolen = floor;
            printf("%d", NEDOVOLEN);
        }
    }
    fprintf(output, "%i", floorOfNedovolen);
    fclose(output);
    return 0;
}
Viewed 833 times, submitted by Guest.