2017上海金马五校程序设计竞赛 A :STEED Cards

Time Limit: 1 s

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  N th  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个字符串。

解题思路:

用STL中的全排列函数 next_permutation。

注意:

字典序排序序号是从1开始的。


代码:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string.h>
#include <map>
using namespace std;
string s[65];
void pailie()
{
    char str[10];
    str[0]='D';
    str[1]='E';
    str[2]='E';
    str[3]='S';
    str[4]='T';
    int j=1;
    map<string,int>M;
    do
    {
        string ss="";
        for(int i=0; i<5; i++)
        {
            ss+=str[i];
        }
        if(M[ss]==0)///判断字符串是否出现过
        {
            M[ss]=j;
            s[j]=ss;
            j++;
        }
    }while(next_permutation(str,str+5));
}
int main()
{
    pailie();
    int n;
    while(~scanf("%d",&n))
    {
        cout<<s[n]<<endl;
    }
    return 0;
}
下边来说一种最开始不知道全排列函数是的暴力列举的代码。由于字母数不多,所以暴力也过了。
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
    int i;
    string s[60];
    s[0]="DEEST";
    s[1]="DEETS";
    s[2]="DESET";
    s[3]="DESTE";
    s[4]="DETES";
    s[5]="DETSE";
    s[6]="DSEET";
    s[7]="DSETE";
    s[8]="DSTEE";
    s[9]="DTEES";
    s[10]="DTESE";
    s[11]="DTSEE";
    s[12]="EDEST";
    s[13]="EDETS";
    s[14]="EDSET";
    s[15]="EDSTE";
    s[16]="EDTES";
    s[17]="EDTSE";
    s[18]="EEDST";
    s[19]="EEDTS";
    s[20]="EESDT";
    s[21]="EESTD";
    s[22]="EETDS";
    s[23]="EETSD";
    s[24]="ESDET";
    s[25]="ESDTE";
    s[26]="ESEDT";
    s[27]="ESETD";
    s[28]="ESTDE";
    s[29]="ESTED";
    s[30]="ETDES";
    s[31]="ETDSE";
    s[32]="ETEDS";
    s[33]="ETESD";
    s[34]="ETSDE";
    s[35]="ETSED";
    s[36]="SDEET";
    s[37]="SDETE";
    s[38]="SDTEE";
    s[39]="SEDET";
    s[40]="SEDTE";
    s[41]="SEEDT";
    s[42]="SEETD";
    s[43]="SETDE";
    s[44]="SETED";
    s[45]="STDEE";
    s[46]="STEDE";
    s[47]="STEED";
    s[48]="TDEES";
    s[49]="TDESE";
    s[50]="TDSEE";
    s[51]="TEDES";
    s[52]="TEDSE";
    s[53]="TEEDS";
    s[54]="TEESD";
    s[55]="TESDE";
    s[56]="TESED";
    s[57]="TSDEE";
    s[58]="TSEDE";
    s[59]="TSEED";
    while(~scanf("%d",&i))
        cout<<s[i-1]<<endl;
}







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值