zoukankan      html  css  js  c++  java
  • 2017年上海金马五校程序设计竞赛:Problem A : STEED Cards (STL全排列函数)

    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
    

    分析:

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

    代码:

    #include<stdio.h>
    #include<iostream>
    #include<algorithm>
    #include<stdlib.h>
    using namespace std;
    int main()
    {
        char ch[10]= {'D','E','E','S','T'};
        string str[150]= {"DEEST"}; ///首先肯定得有第一个才可以
        int ans=0,n;
        do
        {
            for(int i=0; i<5; i++)
            {
                str[ans][i]=ch[i];
            }
            ans++;
        }
        while(next_permutation(ch,ch+5));///直接用全排列函数先打表
        while(~scanf("%d",&n))
        {
            cout<<str[n-1]<<endl;///直接输出来就行
        }
        return 0;
    }
  • 相关阅读:
    [转]给明年依然年轻的我们:欲望、外界、标签、天才、时间、人生目标、现实、后悔、和经历
    C#后台发送HTTP请求
    asp.net 用户控件
    P1414 又是毕业季II
    P2254 [NOI2005]瑰丽华尔兹
    P1081 开车旅行
    P1084 疫情控制
    P1852 [国家集训队]跳跳棋
    P1074 靶形数独
    平时二十三测
  • 原文地址:https://www.cnblogs.com/cmmdc/p/6941041.html
Copyright © 2011-2022 走看看