Friday, April 29, 2016

UVA10163 : Last Digit -solution

Unknown
#include<cstdio>
#include<math.h>
#include<string.h>
using namespace std;

int main()
{
    int a[21]={4,1,5,2,8,3,9,2,8,7,7,8,4,7,3,8,4,1,5,4,4};
    int a4[5]={0,4,8,2,6};
    char n[111];
    while (scanf("%s",n)!=EOF)
    {
        int l=strlen(n);
        if (l==1 && n[0]=='0') return 0;
        int d,r,ans;
        if (l==1) d=n[0]-48;
        else if (l==2) d=(n[0]-48)*10+n[1]-48;
        else d=(n[l-3]-48)*100+(n[l-2]-48)*10+n[l-1]-48;
        if (d==0)
        {
        printf("0\n");
        continue;
        }
        r=d/20;
        d=d%20;
        if (d==0) r--;
        r=r%5;
        ans=(a[d]+a4[r])%10;
        printf("%d\n",ans);
    }
    return 0;
}

Unknown

Studying at Shahjalal University of Science and Technology, Sylhet.

0 comments:

Post a Comment

Coprights @ 2016,