Educational Codeforces Round 54 (Rated for Div. 2) A. Minimizing the String
阿新 • • 發佈:2018-12-21
貪心
因字典序位越靠前權越大
從初始位置列舉此位後一位向後與原串比較字典序
若小則為最優
輸出結束
/* Zeolim - An AC a day keeps the bug away */ //pragma GCC optimize(2) #include <cstdio> #include <iostream> #include <cstdlib> #include <cmath> #include <cctype> #include <string> #include <cstring> #include <algorithm> #include <stack> #include <queue> #include <set> #include <sstream> #include <map> #include <ctime> #include <vector> #include <fstream> #include <list> #include <iomanip> #include <numeric> using namespace std; typedef long long ll; const int MAXN = 1e6 + 10; char arr[MAXN]; int main() { //ios::sync_with_stdio(false); //cin.tie(0); cout.tie(0); //freopen("D://test.in", "r", stdin); //freopen("D://test.out", "w", stdout); int n; scanf("%d%s", &n, arr); for(int i = 0; i < n; i++) { for(int j = i + 1; j < n + 1; j++) { if(arr[j] < arr[i]) { for(int k = 0; k < n; k++) { if(k != i) printf("%c", arr[k]); } goto l1; } else { break; } } } l1: printf("\n"); return 0; }