首页 > 其他分享 >E1. Erase and Extend (Easy Version)

E1. Erase and Extend (Easy Version)

时间:2022-10-08 18:15:14浏览次数:58  
标签:Version cout int cin 首端 Erase Easy E1

传送门

题意:
两种操作,一种是删最尾端的字符,一种是s = s + s(s代表剩下的字符串)求经过这两个操作能够到达的最小的字符串


思路:
贪心的取即可,每回合首端进行比较,首端相等就连续着比较,直到不相等,当前位比mod之后那一位大位置,最后模数就是答案


总结:
对于循环节的输出可以使用取余,对于循环的比较也可以用取余,比较的巧妙,学到了

点击查看代码
#include <bits/stdc++.h>
#define endl '\n'
#define IOS ios::sync_with_stdio(false);
using namespace std;

typedef long long ll;

int n, k;
string s;

int main()
{
	IOS; cin.tie(0), cout.tie(0);
    cin >> n >> k;
    cin >> s;
    if (n == 1)
    {
        for (int i = 0; i < k; ++i)
            cout << s[0];
        cout << endl; 
        exit(0);
    }
    int  mod = 1;
    for (int i = 0; i < s.size(); ++i)
    {
        if (s[i] < s[i % mod])
            mod = i + 1;
        if (s[i] > s[i % mod])
            break;
    }
    
    for (int i = 0; i < k; ++i)
        cout << s[i % mod];
	return 0;
}
/*
8 16
dbdaaaac
*/

标签:Version,cout,int,cin,首端,Erase,Easy,E1
From: https://www.cnblogs.com/jumo-xiao/p/16769764.html

相关文章