forked from oeddyo/algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanswer2.cpp
More file actions
50 lines (38 loc) · 1 KB
/
answer2.cpp
File metadata and controls
50 lines (38 loc) · 1 KB
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
#include <iostream>
#include <string>
using namespace std;
string number;
int helper(string num){
int sz = num.size();
bool should_double = true;
int check_sum = 0;
for(int i=sz-1; i>=0; i--){
int cur_digit = num[i]-'0'; //assume all are number digits
if(should_double==1){
cur_digit *= 2;
}
should_double = !should_double;
if(cur_digit>=10){
int tmp = cur_digit%10;
tmp += (cur_digit/10)%10;
cur_digit = tmp;
}
check_sum += cur_digit;
}
return check_sum;
}
int getFullAccountNumber(string number){
int current_check_sum = helper(number);
//cout<<"current checksum = "<<current_check_sum<<endl;
int tmp = (10 - current_check_sum%10)%10;
return tmp;
}
int main(){
while(cin>>number){
int ans = getFullAccountNumber(number);
string whole_number = number;
number += (ans + '0');
cout<<"OUTPUT: "<<number<<endl;
}
return 0;
}