Advertisement
Guest User

05.Equal Sums Left RIght Position

a guest
Jul 16th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main(){
  5. int a, b;
  6. cin >> a >> b;
  7.  
  8. for(int first = 1 ; first <= 9; first++){
  9. for(int second = 0; second <= 9; second++){
  10. for(int third = 0; third <= 9; third++){
  11. for(int fourth = 0; fourth <= 9; fourth++){
  12. for(int fifth = 0; fifth <= 9; fifth++){
  13.  
  14. int number = 10000 * first + 1000 * second + 100 * third + 10 * fourth + fifth;
  15.  
  16. if(number >= a && number <= b) {
  17. if(fifth + fourth == first + second){
  18. cout << number << " ";
  19. } else if(fifth + fourth < first + second){
  20. bool sum = fifth + fourth + third == first + second;
  21. if(sum){
  22. cout << number << " ";
  23. }
  24. } else if(fifth + fourth > first + second) {
  25. bool sum = fifth + fourth == first + second + third;
  26. if(sum){
  27. cout << number << " ";
  28. }
  29. }
  30. }
  31. }
  32. }
  33. }
  34. }
  35. }
  36.  
  37. return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement