You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
659 B

2 years ago
#include <bits/stdc++.h>
using namespace std;
int a[9];
int cnt = 1;
/*计数,需要注意的是它 = 1。
3 123
*/
int main() {
int n;
cin >> n;//输入,不用说了吧
for (int i = 0; i < n; i++) {
char c;
cin >> c; //char只有一个字符不用担心
a[i] = c - '0'; //记录数字,如果不减字符0表示是存入了字符对应的ascii码值
}
while (prev_permutation(a, a + n)) {//当他还有上一个字典序排列时,计数++。
cnt++;
}
cout << cnt;//输出
return 0; //完结撒花
}