Pagini recente » Cod sursa (job #466404) | Cod sursa (job #2941410) | Cod sursa (job #846160) | Cod sursa (job #42322) | Cod sursa (job #1157209)
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int v[]={0,1,5,2,8,3,9,2,8,7};
char s[150],temp[150];
inline void inmultire()
{
int i;
memcpy(temp,s,sizeof(s));
temp[0]=strlen(temp+1);
reverse(temp+1,temp+temp[0]);
temp[temp[0]]=0;
temp[0]--;
for(i=1;i<=temp[0];i++)
temp[i]-='0';
int trans=0;
for(i=1;i<=temp[0];i++)
{
temp[i]=temp[i]*7+trans;
trans=0;
if(temp[i]>10)
{
trans=temp[i]/10;
temp[i]%=10;
}
}
if(trans)
{
temp[0]++;
temp[temp[0]]=trans;
}
}
inline void adunare(int x)
{
int i,trans;
trans=0;
temp[1]+=x;
if(temp[1]>10)
{
trans=temp[1]/10;
temp[1]%=10;
}
for(i=2;i<=temp[0]&&trans;i++)
{
temp[i]+=trans;
trans=0;
if(temp[i]>10)
{
trans=temp[i]/10;
temp[i]%=10;
}
}
}
int main()
{
int t,i,n;
freopen("cifra.in","r",stdin);
freopen("cifra.out","w",stdout);
scanf("%d\n",&t);
for(i=1;i<=t;i++)
{
memset(temp,0,sizeof(temp));
memset(s,0,sizeof(s));
gets(s+1);
n=strlen(s+1);
inmultire();
adunare(v[s[n]-'0']);
printf("%d\n",temp[1]);
}
return 0;
}