Advertisement
FazEN

Untitled

Mar 17th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include<iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. void x(int *a)
  6. {
  7.  
  8. int i1=0;
  9. int f1=*a;
  10. int s1=0;
  11. int c1=0;
  12. int a3=*a;
  13. int f=*a;
  14. while (*a!=0)
  15. {
  16.  
  17. ++i1;
  18. c1=*a%10;
  19. *a/=10;
  20.  
  21. }
  22.  
  23.  
  24. do
  25. {
  26. int k=pow(10,i1);
  27. s1+=f1/k;
  28. f1%=k;
  29.  
  30. --i1;
  31. } while (i1!=0);
  32. int a2=s1+f%10;
  33. int a1=a2/10+a2%10;
  34. int a4=0;
  35.  
  36. if (a2/10+a2%10>=10) {
  37. int a4=a2/10+a2%10;
  38. a1=a4/10+a4%10;
  39. *a=a4+a3+a2+a1;
  40. }
  41. else {
  42. if (a1==a2 && a1) {
  43. *a=a3+a1;
  44. }else {
  45. *a=a3+a2+a1;
  46.  
  47. }
  48. }
  49.  
  50.  
  51.  
  52. }
  53.  
  54. int main() {
  55.  
  56.  
  57. int b=0;
  58. cin>>b;
  59. if (b<10)
  60. {
  61. cout<<b;
  62. }
  63. else if (b==10 || (b>11 && b<19))
  64. {
  65. cout<<-1;
  66. }else
  67. {
  68.  
  69. for (int i=b;i>=floor(b/1.5);--i)
  70. {
  71. int g=i;
  72. x(&g);
  73.  
  74.  
  75. if (g==b)
  76. {
  77. cout<<i;
  78. break;
  79. }
  80. else if (i == b -200 || i == floor(b / 1.5) )
  81. {
  82. cout<<-1;
  83. break;
  84. }
  85. }
  86. }
  87.  
  88. return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement