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


Problem A : STEED Cards


 (Out of Contest)

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 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

这次比赛还是老样子,简单题都写出来了,难的都没A过,先把做出的题出个题解。

题意:

对DEEST这几个字符组成的字符串按照字典序排序,重复的字符串肯定是只按一个算的,然后输出n,输出第n个字符串。

解题:

STL全排列函数+STL中的map(用映射看一个字符串出没出现过)

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
using namespace std;
string s[65];
void Create_Table()
{
     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()
{
    Create_Table();
    int n;
    while(~scanf("%d",&n))
    {
        cout<<s[n]<<endl;
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值