2017年上海金马五校程序设计竞赛之STEED Cards

来源:互联网 发布:买车团购什么软件 编辑:程序博客网 时间:2024/06/06 14:22

Description
Corn does not participate the STEED contest, but he is interested in the word “STEED”. So, Corn writes all permutations of the word “STEED” on different cards and gets 60 cards finally.

Corn sorts these cards in lexicographical order, and marks them from 1 to 60.

Now, Corn gives you a integer N (1 ≤ N ≤ 60), could you tell him the word on the Nth card?

Input
There are multiple test cases (no more than 60).
For each test case, there is one integer N (1 ≤ N ≤ 60) in a line.

Output
For each test case, you should output one line with the word on the Nth card.

Sample Input
1
2
3
4
47
48
49

Sample Output
DEEST
DEETS
DESET
DESTE
STEDE
STEED
TDEES
题意 :给你一个单词“STEED”,按字典序给其排序,输入一个数字n,输出这个序列的第n个序列。
解题思路:直接用c++函数库中的sort()函数和next_permutation()函数,首先从小到大排序,再用next_permutation()求出所有全排列,并打表

#include <iostream>#include <bits/stdc++.h>using namespace std;int main(){    int n;    int a[] ={'S','T','E','E','D'} ;    sort(a,a+5);    string str[65];    int k=0;    do{        for(int i=0;i<5;i++)            str[k][i] = a[i];        str[k][5] = 0;        k++;    }while(next_permutation(a,a+5));    while(~scanf("%d",&n))    {        for(int i=0;i<5;i++)///注意这里不能用cout直接输出            printf("%c",str[n-1][i]);        printf("\n");    }    return 0;}
阅读全文
0 0