非站内题 WA20
  • 板块学术版
  • 楼主Learn_To_Love
  • 当前回复3
  • 已保存回复3
  • 发布时间2024/7/4 10:55
  • 上次更新2024/7/4 13:54:39
查看原帖
非站内题 WA20
1082437
Learn_To_Love楼主2024/7/4 10:55

题目描述 Description 给出一个整数n,现在得到前n个小写字母,a, b, c, ……。试求出这n个小写字母所有排列中的倒数第k个排列。

输入描述 Input Description 第一行,两个正整数,n k

输出描述 Output Description 倒数第k个排列

样例输入 Sample Input 3 6

样例输出 Sample Output abc

代码:

#include<iostream>
  
#include<cstdio>
  
#include<cstring>
  
#include<string>
  
#include <algorithm>
  
#include<cmath>
  
  
using namespace std;
  
int a[1005];
  
int main(){
  
	int n,i,j=1,k,s,cnt=0;
	cin>>n>>s;
	for(i=1;i<=n;i++){
        a[i]=n-i+1;j*=i;
	 }
	for(i=1;i<=j;i++){
	    next_permutation(a+1,a+n+1);
        cnt++;
        if(cnt==s) {
            for(k=1;k<=n;k++){
                 cout<<char(a[n-k+1]+96);
            }
            return 0;
        }
	 }
	 return 0;
}
有没有大佬会dsf的
2024/7/4 10:55
加载中...