Cod sursa(job #1693723)

Utilizator sdwolfSDWOLF sdwolf Data 23 aprilie 2016 19:13:13
Problema Cifra Scor 0
Compilator c Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <stdio.h>
#include <stdlib.h>

int main() {
  FILE *input, *output;
  int  index, size, previous, last, number;
  int  computed[20] = {0, 1, 5, 2, 8, 3, 9, 2, 8, 7, 7, 8, 4, 7, 3, 8, 4, 1, 5, 4};
  char symbol;

  input  = fopen("cifra.in", "r");
  output = fopen("cifra.out", "w");

  fscanf(input, "%d\n", &size);

  for (index = 0; index < size; index += 1) {
    last = -1;
    while (fscanf(input, "%c", &symbol)) {
      if (symbol == '\n') break;

      previous = last;
      last = symbol - 48;
    }

    if (previous == -1) {
      number = last;
    } else {
      number = previous % 2 * 10 + last;
    }

    fprintf(output, "%d\n", computed[number]);
  }

  fclose(input);
  fclose(output);

  return 0;
}