Cod sursa(job #28953)

Utilizator codertuxNistor Andrei codertux Data 8 martie 2007 14:40:30
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.06 kb
/***************************************************************************
 *   Copyright (C) 2007 by Nistor Andrei   *
 *   [email protected]   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/


#include <fstream>

using namespace std;

int ultima(long long x){
	long long y=x%10;
	switch (y){
	case 1: return 1;

	case 2: if ((x/10)%2) return 6;
		else return 4;

	case 3: if ((x/10)%2) return 3;
		else return 7;

	case 4: return 6;

	case 5: return 5;

	case 6: return 6;

	case 7: if ((x/10)%2) return 7;
		else return 3;

	case 8: if ((x/12)%2) return 4;
		else return 6;

	case 9: return 9;

	case 0: return 0;
	}
}

int main(int argc, char *argv[])
{
	long long N, j;
	int T, i, S;

	fstream in("cifra.in", ios::in);
	fstream out("cifra.out", ios::out);

	in>>T;

	for (i=1; i<=T; ++i){
		S=0;
		in>>N;
		for( j=1 ; j<=N ; ++j ){
			S+=ultima(j);
		}
		out<<S%10<<"\n";
	}

	in.close();
	out.close();

	return 0;
}