Cod sursa(job #972236)

Utilizator danlexDan Alexandru danlex Data 11 iulie 2013 12:27:22
Problema Cifra Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <fstream>
#include <string.h>
using namespace std;

int i, j, k, n, out;
char t[101], u[2];
int st[100];

int pow100(int p){
    int p10 = p % 10;
	int pp = 1;
    for (i = 0; i < p; i ++){
        pp *= p10;
		pp %= 10;
    }
    return pp;
}

void compute100(){
    st[1] = 1;
    for(i = 2; i <= 100; i++){
        st[i] = st[i-1] + pow100 (i);
		st[i] %= 10;
    }
}

void read(){
	compute100();
	int l, nr;
    ifstream fi("cifra.in");
	ofstream fo("cifra.out");
    fi >> n;
	for(i = 0; i < n; i ++){
		fi >> t;
		l = strlen(t);
		nr = 0;
		if(l > 1){
			nr = (t[l - 2] - '0') * 10 + (t[l - 1] - '0');
		} else if (strlen(t) == 1) {
			nr = t[l - 1] - '0';	
		}
		fo << st[nr] << endl;
	}
    fi.close();
	fo.close();
}

int main(void){
    read();
    return 0;
}