1. 程式人生 > >Educational Codeforces Round 54 (Rated for Div. 2)A. Minimizing the String(思維)

Educational Codeforces Round 54 (Rated for Div. 2)A. Minimizing the String(思維)

題意:給你一個字串,讓你刪除一個字元,使得到的字串的字典序最小。

思路:根據字典序的特點,我們只要一次比較兩個字元,找到第一個字元大於第二個的字元,則刪除第一個字元即可,要注意aaak這種情況,特判一下就行了。

AC程式碼:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n; string s;
    cin >> n >> s;
    for (int i = 0; i < n; i++)
    {
        if (i == n - 1 || s[i] > s[i + 1])
        {
            for (int j = i + 1; j < n; j++)
                cout << s[j];
            break;
        }
        cout << s[i];
    }
    cout << endl;
    return 0;
}