Cod sursa(job #413554)

Utilizator AndreiRSStatescu Andrei Rares AndreiRS Data 8 martie 2010 18:57:24
Problema Koba Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.43 kb
#include <stdio.h>

int n,t1,t2,t3;
int i;
int x,s;

int main(){
	
	FILE*f1=fopen("koba.in","r");
	fscanf(f1,"%d %d %d %d\n",&n,&t3,&t2,&t1);
	fclose(f1);
	
	t1%=10;
	t2%=10;
	t3%=10;
	
	if(n>=1)
		s+=t1;
	if(n>=2)
		s+=t2;
	if(n>=3)
		s+=t3;
	for(i=4; i<=n; i++){
		x = (t1+t2*t3)%10;
		s+=x;
		t3=t2;
		t2=t1;
		t1=x;		
	}

	FILE*f2=fopen("koba.out","w");
	fprintf(f2,"%d",s);
	fclose(f2);	
	
	return 0;
}