Cod sursa(job #137253)

Utilizator kojocojocaru aurelian kojo Data 17 februarie 2008 10:36:59
Problema Koba Scor 30
Compilator cpp Status done
Runda preONI 2008, Runda 4, Clasele 5-8 Marime 0.34 kb
#include<fstream.h>
ifstream f("koba.in");
ofstream g("koba.out");
long n,i,s;
int t1,t2,t3,x;
int main()
{
f>>n>>t1>>t2>>t3;
if(n==1)
  s=t1%10;
if(n==2)
  s=t1%10+t2%10;
if(n==3)
  s=t1%10+t2%10+t3%10;
if(n>3)
	{s=t1%10+t2%10+t3%10;
	 for(i=4;i<=n;i++)
	 {x=(t3%10+t2%10*t1%10)%10;s+=x;t1=t2;t2=t3;t3=x;}
	}
g<<s;
return 0;
}