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
思路:将全排列的字符串放在二位数组里打表,
代码:
#include <iostream>
#include<cstdio>
#include <algorithm> /// next_permutation, sort
using namespace std;
int main () {
int myints[] = {83,84,69,69,68};
sort (myints,myints+5);
char b[100][5];
int i=0;
do {
b[i][0]=myints[0];
b[i][1]=myints[1];
b[i][2]=myints[2];
b[i][3]=myints[3];
b[i][4]=myints[4];
b[i][5]='\0';
/// cout<<b[i][0]<<b[i][1]<<b[i][2]<<b[i][3]<<b[i][4]<<endl;
/// printf("%s\n",b[i]);
i++;
} while ( next_permutation(myints,myints+5) );///获取下一个较大字典序排列
///printf("%d\n",i);
int n;
while(cin>>n)
{
cout<<b[n-1][0]<<b[n-1][1]<<b[n-1][2]<<b[n-1][3]<<b[n-1][4]<<endl;
}
return 0;
}