Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- string perm(int num, int pos);
- int main(){
- int a, b, c;
- cin >> a >> b >> c;
- int pos = 0;
- string as = perm(a, pos);
- string bs = perm(b, pos);
- if ((stoi(as) + stoi(bs) == c) && (as[0] != '0') && (bs[0] != '0')){
- cout << "YES";
- cout << stoi(as) << stoi(bs);
- }
- else{
- cout << "NO";
- }
- return 0;
- }
- string perm(int num, int pos){
- string s = to_string(num);
- if (pos > s.length()){
- return(s);
- }
- else{
- for(int i = pos; i < s.length(); i++){
- char buf = s[i];
- s[i] = s[pos];
- s[pos] = buf;
- perm(num, pos++);
- buf = s[i];
- s[i] = s[pos];
- s[pos] = buf;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement