Cod sursa(job #1499498)

Utilizator ChristianCunaCuna Cristian ChristianCuna Data 10 octombrie 2015 18:28:43
Problema Text Scor 0
Compilator c Status done
Runda Arhiva de probleme Marime 1.42 kb
#include <stdio.h>
#include <stdlib.h>

FILE *input, *output;

int a, b, result=0;


void simpla(int a, int b){
    int tens, i;

    if(a % 2 == 0){
        while(a % 10 != 0 && a + 2 <= b){
            a += 2;
            result += 1;
        }
        fprintf(output, "result even: %d\n", result);
    }
    else {
        while(a % 10 != 9 && a + 2 <= b){
            a += 2;
            result += 1;
        }
        a += 1;
        fprintf(output, "result odd: %d\n", result);
    }
    while(a < b){
        tens = 1;
        /**Find the biggest power of 10 which added to a is not greater than b*/
        while(a + 10 * tens <= b)
            tens *= 10;
        /**Find the biggest multiple of tens which add to a is not greater than b*/
        fprintf(output, "tens: %d\n", tens);
        i = 1;
        while(a + tens * (i+1) <= b){
            ++i;
        }
        tens *= i;
        fprintf(output, "tens: %d\n", tens);
        if(tens == 1){
            while(a <= b){
                a += 2;
                result += 1;
            }
            return;
        }
        a += tens;
        result = result + tens / 2;
        fprintf(output, "result: %d\n", result);
    }

    return;
}

int main()
{
    input = fopen("simpla.in", "r");
    output = fopen("simpla.out", "w");

    fscanf(input, "%d %d", &a, &b);

    simpla(a, b);

    fprintf(output, "%d", result);

    fclose(input);
    fclose(output);

    return 0;
}