-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11743 - Credit Check
101 lines (83 loc) · 1.75 KB
/
11743 - Credit Check
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <bits/stdc++.h>
using namespace std;
int dig (int n)
{
int g = 0;
while(n > 0)
{
g = g + n % 10;
n = n / 10;
}
return g;
}
int main()
{
string s;
int tes;
cin >> tes;
getchar();
while(tes--)
{
getline(cin ,s );
string s3 = "", s2 ="" , s1 = "";
for(int i = 0; i < s.length(); i += 1)
{
if(s[i] >= '0' and s[i] <= '9')
s3 += s[i];
}
int p = 1 , k = 0;
for(int i = 0; i < s3.length(); i += 2)
{
s1 += s3[i];
}
for(int i = 1; i < s3.length(); i += 2)
{
s2 += s3[i];
}
vector <int> vc, vk , vm , vp;
int x = 0;
for(int i = 0; i < s1.length(); i++)
{
x = s1[i] - 48;
vc.push_back(x);
}
int l = 0 , kk;
for(int i = 0; i < vc.size(); i++)
{
l = vc[i] * 2;
vk.push_back(l);
}
for(int i = 0; i < vk.size(); i++)
{
if(vk[i] > 9)
{
kk = dig(vk[i]);
vm.push_back(kk);
}
else
{
vm.push_back(vk[i]);
}
}
int sum1 = 0;
for(int i = 0; i < vm.size(); i++)
{
sum1 += vm[i];
}
int f = 0;
int sum2 = 0;
for(int i = 0; i < s2.length(); i++)
{
f = s2[i] - 48;
sum2 += f;
}
int sum3 = sum1 + sum2;
if(sum3 % 10 == 0)
printf("Valid\n");
else
printf("Invalid\n");
vm.clear();
vk.clear();
vc.clear();
}
}