Cod sursa(job #715587)

Utilizator lukkerLiNoimi Semain lukker Data 17 martie 2012 14:57:16
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <iostream>
#include <fstream>
#include <time.h>
using namespace std;

ifstream f("cifra.in");
FILE *f2=fopen("cifra.out","w");

int per[100]={1,4,7,6,5,6,3,6,9,0,1,6,3,6,5,6,7,4,9,0,1,4,7,6,5,6,3,6,9,0,1,6,3,6,5,6,7,4,9,0,1,4,7,6,5,6,3,6,9,0,1,6,3,6,5,6,7,4,9,0,1,4,7,6,5,6,3,6,9,0,1,6,3,6,5,6,7,4,9,0,1,4,7,6,5,6,3,6,9,0,1,6,3,6,5,6,7,4,9,0};

int main() {
	int n;
	int s=0;
	char t[102];
	f>>n;
	f.getline(t,100);
	while(n>0) {
		char a[102];
		s=0;
		int i=0;
		f.getline(a,100);
		for(int k=0;k<=100;k++) {
			i=k-1;
			if(a[k]==0) break;
		}
		int m;
		if(i<10) m=a[i]-48;
		else m=(a[i-1]-48)*10+a[i]-48;
		for(int k=1;k<=100;k++) {
			int tot=i/2+1;
			if(k>m) tot--;
			s+=tot*per[k-1];
		}
		s%=10;
		fprintf(f2,"%d \n",s);
		n--;
	}
	return 0;
}