Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. string perm(int num, int pos);
  7.  
  8. int main(){
  9. int a, b, c;
  10. cin >> a >> b >> c;
  11. int pos = 0;
  12. string as = perm(a, pos);
  13. string bs = perm(b, pos);
  14. if ((stoi(as) + stoi(bs) == c) && (as[0] != '0') && (bs[0] != '0')){
  15. cout << "YES";
  16. cout << stoi(as) << stoi(bs);
  17. }
  18. else{
  19. cout << "NO";
  20. }
  21. return 0;
  22. }
  23.  
  24. string perm(int num, int pos){
  25. string s = to_string(num);
  26. if (pos > s.length()){
  27. return(s);
  28. }
  29. else{
  30. for(int i = pos; i < s.length(); i++){
  31. char buf = s[i];
  32. s[i] = s[pos];
  33. s[pos] = buf;
  34. perm(num, pos++);
  35. buf = s[i];
  36. s[i] = s[pos];
  37. s[pos] = buf;
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement