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

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#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; //完结撒花
}