Cod sursa(job #1668073)

Utilizator andreea.ionut98Andreea Ionut andreea.ionut98 Data 29 martie 2016 15:40:34
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include<iostream>
#include<fstream>

using namespace std;

ifstream f("cifra.in");
ofstream g("cifra.out");

int uc(int x)
{
	int c=x%10;
	if(c==1 || c==0)
		return c;
	if(c==2 || x==8)
		return 4;
	if(c==3)
		return 7;
	if(c==4 || c==6)
		return 6;
	if(c==5)
		return 5;
	if(c==7)
		return 3;
	if(c==9)
		return 9;
	return 0;
}

int suma(int poz)
{
	int s=0, i;
	for(i=1;i<=poz;i++)
		s+=uc(i);
	return s%10;
}

int cifra(char n[])
{
	int c=n[strlen(n)-1]-'0';
	int s;
	s=suma(c);
	return s;
}

void citire(int T)
{
	f>>T;
	f.get();
	char n[255];
	int i;
	for(i=1;i<=T;i++)
	{
		f.getline(n, 255);
		g<<cifra(n)<<endl;
	}
}

int main()
{
	int T;
	citire(T);
	return 0;
}