Problem A : STEED Cards
From: DHUOJ, 2017060301
(Out of Contest)
这次比赛还是老样子,简单题都写出来了,难的都没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;
}