Advertisement
FazEN

Untitled

Mar 17th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 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. if (a1>10) {
  35. a1/=2;
  36. a2-=a1;
  37. }
  38. else {
  39.  
  40.  
  41. if (a1==a2 && a1) {
  42. *a=a3+a1;
  43. }else {
  44. *a=a3+a2+a1;
  45.  
  46. }
  47. }
  48.  
  49. }
  50.  
  51. int main() {
  52. // long long int s,a2,f,b,c;
  53. // bool x=false;
  54.  
  55. // int c1=0;
  56. // int i1=0;
  57. // int s1=0;
  58. // cin>>b;
  59. // for ( int d=1;d<=9;++d) {
  60. // s=0;
  61. // i1=0;
  62. // for (int i=1;i<=9;++i) {
  63. // for (int j=0;j<=9;++j) {
  64. // if (i+j==d)
  65. // {
  66. // a2=i*10+j;
  67. // s=d+a2;
  68. // f=b-s;
  69. // long long int f1=f;
  70.  
  71. // long long int b1=f;
  72. // while (f!=0) {
  73.  
  74. // ++i1;
  75. // c1=f%10;
  76. // f/=10;
  77.  
  78. // }
  79.  
  80.  
  81. // do {
  82. // int k=pow(10,i1);
  83. // s1+=f1/k;
  84. // f1%=k;
  85.  
  86. // --i1;
  87. // } while (i1!=0);
  88.  
  89.  
  90. // if (s1+b1%10==a2)
  91. // {
  92. // cout<<b1;
  93. // x=true;
  94. // }
  95. // else if (d==9 && s+b1%10!=a2 && a2==90)
  96. // {
  97. // cout<<-1;
  98. // x=true;
  99. // }
  100.  
  101.  
  102.  
  103. // }
  104. // if (x==true) {
  105. // break;
  106. // }
  107.  
  108. // }
  109. // if (x==true) {
  110. // break;
  111. // }
  112.  
  113. // }
  114. // if (x==true) {
  115. // break;
  116. // }
  117. // }
  118.  
  119.  
  120. int b, i, g;
  121. cin>>b;
  122. if (b<10){
  123. cout<<b;
  124. }
  125. else if (b==10)
  126. {
  127. cout<<-1;
  128. }
  129. else
  130. {
  131. for (i=b;i>b/1.5;--i)
  132. {
  133. g=i;
  134. x(&g);
  135. if (g==b)
  136. break;
  137. else if (i == b - 200)
  138. break;
  139. }
  140. }
  141. if (i == floor(b / 1.5))
  142. {
  143. cout << -1;
  144. }
  145. else if (i == b - 200)
  146. {
  147. cout << -1;
  148. }
  149. else
  150. {
  151. cout << i;
  152. }
  153.  
  154. return 0;
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement