fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int check(int n){
  5. int f,l,temp,sumf=0,suml=0;
  6. f = n/1000;
  7. l = n%1000;
  8. temp=f;
  9. while(temp!=0){
  10. sumf+= temp%10;
  11. temp=temp/10;
  12. }
  13. temp=l;
  14. while(temp!=0){
  15. suml+= temp%10;
  16. temp=temp/10;
  17. }
  18. if(sumf==suml){
  19. return n;
  20. }
  21. else{
  22. n++;
  23. check(n);
  24. }
  25. }
  26.  
  27. int main() {
  28. int n,dig=0,val,temp;
  29. cin >> n;
  30. temp = n;
  31. while(temp!=0){
  32. temp= temp/10;
  33. dig++;
  34. }
  35. if(dig!=6){
  36. cout<<"100001";
  37. }
  38. else{
  39. n++;
  40. val=check(n);
  41. cout<<val;
  42. }
  43. return 0;
  44. }
Success #stdin #stdout 0s 16064KB
stdin
555555
stdout
555564