#include <iostream> #include <stdlib.h> #include <math.h> using namespace std; string input; int counter = 0; int intcel; bool check(int a, int b) { int buf[input.length()]; int cel[input.length()]; for(int i =0; i<input.length(); i++){ buf[i] = 0; cel[i] = ((int)input[i])-48; } int i = a; int len = 1; if (i > 0) { for (len = 0; i > 0; len++) { i = i / 10; } } int alen = len; i = b; len = 1; if (i > 0) { for (len = 0; i > 0; len++) { i = i / 10; } } int blen = len; if (alen>blen)len = alen; int a_aar[len]; int b_aar[len]; for(int i =0; i<len; i++){ a_aar[i] = 0; b_aar[i] = 0; } for(int i =len-1; i>=0; i--) { a_aar[i] = a%10; a-=a%10; a/=10; b_aar[i] = b%10; b-=b%10; b/=10; } bool wynik = true; int mod= 0; for(int i =0; i<len; i++) { if(a_aar[i]+b_aar[i]<10) buf[i+mod] =a_aar[i]+b_aar[i]; else{ buf[i+mod] = 1; mod++; buf[i+mod] = (a_aar[i]+b_aar[i])%10; if (i+mod>input.length()){ wynik = false; break; } } } for(int i = 0; i<input.length(); i++) if(buf[i]!=cel[i]) wynik = false; return wynik; } int main() { cin>>input; intcel = atoi(input.c_str()); for(int i =0; i<=intcel; i++) for(int j =0; j<= intcel; j++) if(check(i,j)) counter++; cout<<counter; 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 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 101 102 103 104 105 | #include <iostream> #include <stdlib.h> #include <math.h> using namespace std; string input; int counter = 0; int intcel; bool check(int a, int b) { int buf[input.length()]; int cel[input.length()]; for(int i =0; i<input.length(); i++){ buf[i] = 0; cel[i] = ((int)input[i])-48; } int i = a; int len = 1; if (i > 0) { for (len = 0; i > 0; len++) { i = i / 10; } } int alen = len; i = b; len = 1; if (i > 0) { for (len = 0; i > 0; len++) { i = i / 10; } } int blen = len; if (alen>blen)len = alen; int a_aar[len]; int b_aar[len]; for(int i =0; i<len; i++){ a_aar[i] = 0; b_aar[i] = 0; } for(int i =len-1; i>=0; i--) { a_aar[i] = a%10; a-=a%10; a/=10; b_aar[i] = b%10; b-=b%10; b/=10; } bool wynik = true; int mod= 0; for(int i =0; i<len; i++) { if(a_aar[i]+b_aar[i]<10) buf[i+mod] =a_aar[i]+b_aar[i]; else{ buf[i+mod] = 1; mod++; buf[i+mod] = (a_aar[i]+b_aar[i])%10; if (i+mod>input.length()){ wynik = false; break; } } } for(int i = 0; i<input.length(); i++) if(buf[i]!=cel[i]) wynik = false; return wynik; } int main() { cin>>input; intcel = atoi(input.c_str()); for(int i =0; i<=intcel; i++) for(int j =0; j<= intcel; j++) if(check(i,j)) counter++; cout<<counter; return 0; } |