#include #include using namespace std; string number; bool validNumber(string num){ int sz = num.size(); if(sz == 0)return true; for(int i=0; i='0' && num[i]<='9')){ return false; //not valid } } return true; } bool isValid(string num){ if(!validNumber(num)){ cout<=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; } check_sum += num[sz-1]-'0'; if(check_sum % 10 == 0){ return true; }else{ return false; } } 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){ if(!validNumber(number)){ return -1; // or throw an exception but I forget the syntax } int current_check_sum = helper(number); int tmp = (10 - current_check_sum%10)%10; return tmp; } int main(){ //call some function here //test here // bool all_passed = true; if(!isValid("")){ all_passed = false; cout<<"didn't pass empty string"<