Uva 11743 - Credit Check
#include<iostream>
#include<cmath>
#include<string>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long int LL;
LL digit_sum(LL n)
{
LL sum=0;
while(n)
{
sum+=(n%10);
n/=10;
}
return sum;
}
bool isCheck(LL n)
{
return n%10;
}
int main()
{
int t;
cin >> t;
getchar();
string s;
while(t--)
{
getline(cin,s);
LL len = s.size(),i,ds=0;
for(i=0;i<len;i+=2)
{
if(s[i]==' ')i++;
ds+=(digit_sum((s[i]-48)*2))+(s[i+1] - 48);
}
//cout << ds << endl;
if(!isCheck(ds))
{
cout << "Valid" << endl;
}
else
{
cout << "Invalid" << endl;
}
}
return 0;
}
#include<cmath>
#include<string>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long int LL;
LL digit_sum(LL n)
{
LL sum=0;
while(n)
{
sum+=(n%10);
n/=10;
}
return sum;
}
bool isCheck(LL n)
{
return n%10;
}
int main()
{
int t;
cin >> t;
getchar();
string s;
while(t--)
{
getline(cin,s);
LL len = s.size(),i,ds=0;
for(i=0;i<len;i+=2)
{
if(s[i]==' ')i++;
ds+=(digit_sum((s[i]-48)*2))+(s[i+1] - 48);
}
//cout << ds << endl;
if(!isCheck(ds))
{
cout << "Valid" << endl;
}
else
{
cout << "Invalid" << endl;
}
}
return 0;
}
Comments
Post a Comment