排列序列

c++:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n,k,a[10];
	cin>>n>>k;
	for(ll i=1;i<=9;i++)a[i]=i;
	while(k-1)
	{
		next_permutation(a+1,a+n+1);
		k--;
	}
	cout<<'"';
	for(ll i=1;i<=n;i++)cout<<a[i];
	cout<<'"'<<endl;
	
	return 0;
}
python:

import itertools
x=input()
n=int(x[4])
k=int(x[len(x)-1])
a=[]
for i in range(1,n+1):
    a.append(i)
result=itertools.permutations(a,n)
# print(list(result)[k-1])
print('"',end='')
for i in list(result)[k-1]:
    print(i,end='')
print('"')
全部评论

相关推荐

04-15 13:42
四川大学 Java
蹲蹲offerrr:快投吧,有点晚现在
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务