#include <iostream> #include <string> #include <sstream> using namespace std; string add(long long int a, long long int b){ string out = ""; int greater = 0; if(a > b) { greater = a; } else { greater = b; } while(greater > 0){ int aLast = a % 10; int bLast = b % 10; int c = aLast + bLast; stringstream ss; ss << c; string val = ss.str(); string temp = out; out = val + temp; a /= 10; b /= 10; greater /= 10; } return out; } int main(){ unsigned long long int input = 1010; stringstream ss; ss << input; string inputS = ss.str(); long long int output = 0; for(long long int i = 0; i <= input; i++){ for(long long int j = input; j >= 0; j--){ if(add(i, j) == inputS){ output++; } } } cout << output << endl; return 0; }
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 | #include <iostream> #include <string> #include <sstream> using namespace std; string add(long long int a, long long int b){ string out = ""; int greater = 0; if(a > b) { greater = a; } else { greater = b; } while(greater > 0){ int aLast = a % 10; int bLast = b % 10; int c = aLast + bLast; stringstream ss; ss << c; string val = ss.str(); string temp = out; out = val + temp; a /= 10; b /= 10; greater /= 10; } return out; } int main(){ unsigned long long int input = 1010; stringstream ss; ss << input; string inputS = ss.str(); long long int output = 0; for(long long int i = 0; i <= input; i++){ for(long long int j = input; j >= 0; j--){ if(add(i, j) == inputS){ output++; } } } cout << output << endl; return 0; } |