problem link
Discuss: This is just easy applied problem.You can take input using %1d specifier or using char string.then easily calculate the value and check last digit using remainder.
try yourself before see the code
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c,d,n,i,j,sum,oddsum,totalsum,t,k,r;
cin >>t;
for(k=0;k<t;k++)
{
totalsum=0;
for(i=0;i<4;i++)
{
sum=0;
scanf("%1d%1d%1d%1d",&a,&b,&c,&d);
a*=2;
c*=2;
while(a>0)
{
r=a%10;
a/=10;
sum+=r;
}
while(c>0)
{
r=c%10;
c/=10;
sum+=r;
}
sum+=b;
sum+=d;
totalsum+=sum;
}
r=totalsum%10;
if(r==0)
cout <<"Valid"<<endl;
else
cout <<"Invalid"<<endl;
}
}
No comments:
Post a Comment