• B. Prinzessin der Verurteilung


    Problem - 1536B - Codeforces

    I, Fischl, Prinzessin der Verurteilung, descend upon this land by the call of fate an — Oh, you are also a traveler from another world? Very well, I grant you permission to travel with me.

    It is no surprise Fischl speaks with a strange choice of words. However, this time, not even Oz, her raven friend, can interpret her expressions! Maybe you can help us understand what this young princess is saying?

    You are given a string of nn lowercase Latin letters, the word that Fischl just spoke. You think that the MEX of this string may help you find the meaning behind this message. The MEX of the string is defined as the shortest string that doesn't appear as a contiguous substring in the input. If multiple strings exist, the lexicographically smallest one is considered the MEX. Note that the empty substring does NOT count as a valid MEX.

    A string aa is lexicographically smaller than a string bb if and only if one of the following holds:

    • aa is a prefix of bb, but a≠ba≠b;
    • in the first position where aa and bb differ, the string aa has a letter that appears earlier in the alphabet than the corresponding letter in bb.

    A string aa is a substring of a string bb if aa can be obtained from bb by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.

    Find out what the MEX of the string is!

    Input

    Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤10001≤t≤1000). Description of the test cases follows.

    The first line of each test case contains an integer nn (1≤n≤10001≤n≤1000) — the length of the word. The second line for each test case contains a single string of nn lowercase Latin letters.

    The sum of nn over all test cases will not exceed 10001000.

    Output

    For each test case, output the MEX of the string on a new line.

    Example

    input

    Copy

    3
    28
    qaabzwsxedcrfvtgbyhnujmiklop
    13
    cleanairactbd
    10
    aannttoonn
    

    output

    Copy

    ac
    f
    b
    

     mex 为字符串中未出现的最短的字符串

    直接暴力

    1. #include
    2. #include
    3. #include
    4. #include
    5. #include
    6. #include
    7. #include
    8. #include
    9. #include
    10. #include
    11. using namespace std;
    12. // ctrl+shift+C 注释
    13. //ctrl+shift+x 取消
    14. //#define int long long
    15. #define YES cout<<"YES"<
    16. #define NO cout<<"NO"<
    17. #define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    18. //int k = min_element(a + 1, a + 1 + n) - a
    19. typedef long long ll;
    20. typedef pair<int,int> PII;
    21. const int N=2e5+10;
    22. const ll M=1e18+10;
    23. const int mod=1e9+7;
    24. int a[N],sum[N];
    25. priority_queue<int,vector<int>,greater<int> >pq;
    26. set<int>se;
    27. map<char,int>mp;
    28. queue<int>qu;
    29. vector<int>v;
    30. deque<int>de;
    31. //struct Range
    32. //{
    33. // int l,r;
    34. // bool operator< (const Range &w)const
    35. // {
    36. // return l
    37. // }
    38. //}range[N];
    39. //-----------------------------分割线---------------------------------------------------
    40. int n;
    41. string s;
    42. void solve()
    43. {
    44. cin>>n>>s;
    45. mp.clear();
    46. int k=0;
    47. for(int i=0;i
    48. {
    49. if(!mp[s[i]])k++;
    50. mp[s[i]]++;
    51. }
    52. if(k<26)//没出现的
    53. {
    54. for(int i=0;i<26;i++)
    55. {
    56. if(!mp['a'+i])
    57. {
    58. printf("%c\n",'a'+i);
    59. return;
    60. }
    61. }
    62. }
    63. string ss="aa";//二个的
    64. for(int i=0;i<26;i++)
    65. {
    66. ss[0]='a'+i;
    67. for(int j=0;j<26;j++)
    68. {
    69. ss[1]='a'+j;
    70. if(s.find(ss)==-1)
    71. {
    72. cout<
    73. return;
    74. }
    75. }
    76. }
    77. ss="aaa";//三个的
    78. for(int i=0;i<26;i++)
    79. {
    80. ss[0]='a'+i;
    81. for(int j=0;j<26;j++)
    82. {
    83. ss[1]='a'+j;
    84. for(int m=0;m<26;m++)
    85. {
    86. ss[2]='a'+m;
    87. if(s.find(ss)==-1)
    88. {
    89. cout<
    90. return;
    91. }
    92. }
    93. }
    94. }
    95. }
    96. int main()
    97. {
    98. int t=1;
    99. cin>>t;
    100. while(t--)
    101. {
    102. solve();
    103. }
    104. }

  • 相关阅读:
    YAML 快速上手
    顺序栈算法库构建
    【Java】Map集合
    CSAPP 第九章---虚拟内存
    翻译软件免费版下载
    【字符串】重复的DNA序列
    UE必学系列(基础篇完结)
    Python基础入门篇【22】--python中的函数:初时函数及函数的参数
    C++ STL --- vector的使用
    Kotlin高仿微信-第36篇-支付-设置金额
  • 原文地址:https://blog.csdn.net/qq_62079079/article/details/127735685