Pagini recente » Cod sursa (job #685527) | Cod sursa (job #595195) | Cod sursa (job #808115) | Monitorul de evaluare | Cod sursa (job #1693723)
#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;
}