Cod sursa(job #913348)

Utilizator TibixbAndrei Tiberiu Tibixb Data 13 martie 2013 12:35:21
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 kb
#include<fstream>
#include<string.h>
using namespace std;
int T, t, exp, rest, p, nr;
char c[105];
ifstream f("cifra.in");
ofstream g("cifra.out");
int main(){
    f>>T;
    for(;T!=0;T--){
        f>>c;
        t=strlen(c);
        if(t>1){
            c[t-1]-='0';
            c[t-2]-='0';
            exp=c[t-2]*10+c[t-1];
            rest=exp%4;
            if(rest==0)
                rest=4;
                p=1;
            while(rest!=0){
                p*= c[t-1];
                rest--;
            }
            nr+=p%10;
            nr%=10;
            g<<p%10<<"\n";
        }
        if(t==1){
            c[t-1]-='0';
            //c[t-2]-='0';
            exp=c[t-1];
            rest=exp%4;
            if(rest==0)
                rest=4;
                p=1;
            while(rest!=0){
                p*=c[t-1];
                rest--;
            }
            nr+=p%10;
            nr%=10;
            g<<nr<<"\n";
        }
    }
return 0;
}