forked from ravikartar/hacktober2022
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolve_next.cpp
More file actions
37 lines (35 loc) · 782 Bytes
/
solve_next.cpp
File metadata and controls
37 lines (35 loc) · 782 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
void display(vector<int> a, long long & n, long long &sum) {
n++;
for (long unsigned int i = 0; i < a.size(); i++)
{cout << a[i] << " "; sum += a[i];}
cout << endl;
}
int main() {
long n;
cin >> n;
vector<int> a;
while (n)
{
a.push_back(n % 10);
n /= 10;
}
for (auto x : a)
cout << x << " ";
cout << endl;
reverse(a.begin(), a.end());
set<vector<int>> st;
long long count = 0, sum = 0;
do {
display(a, count, sum);
} while (next_permutation(a.begin(), a.end()));
cout << count << " " << sum << "\n";
return 0;
}