Lexicographic Order

(https://codeforces.com/group/L9GOcnr1dm/contest/422381/problem/L)

比较简单的一道题目,主要理解什么是字典序就好了

它要求我们以给定的字符串去构建一个最大字典序的字符串且长度不超过m

那么我们能知道最大字典序(小写的)肯定就是‘z’所以我们需要添加m-n个‘z’即可。

再然后我们需要满足构造的新字符串的字典序要小于原字符串,那么我们只需要修改原字符串的最后一个字母

PS:这里要考虑最后一个字符是否是‘a’的情况

如果是,那么直接删去‘a’即可构造完毕,不需要再添加‘z’(特殊情况!)

反之要添加‘z’;

Acode

string s = "abcdefghijklmnopqrstuvwxyz";
int main() {
int n,m;cin >> n >> m;
string aim;cin >> aim;
if(aim[aim.size()-1] == 'a'){
for (int i = 0; i < aim.size()-1; i++) {
cout << aim[i];
}
cout << endl;
}else{
for (int i = 0; i < s.size(); i++) {
if(s[i] == aim[aim.size()-1]){
aim[aim.size()-1] = s[i-1];break;
}
}
string ad;
for (int i = 1; i <= m-n; i++) {
ad += 'z';
}
string ans = aim + ad;
cout << ans << endl;
}
return 0;
}

Lexicographic Order的更多相关文章

  1. HDU 3999 The order of a Tree

    The order of a Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  2. hdu3999The order of a Tree (二叉平衡树(AVL))

    Problem Description As we know,the shape of a binary search tree is greatly related to the order of ...

  3. <hdu - 3999> The order of a Tree 水题 之 二叉搜索的数的先序输出

    这里是杭电hdu上的链接:http://acm.hdu.edu.cn/showproblem.php?pid=3999  Problem Description: As we know,the sha ...

  4. HDU 3999 The order of a Tree (先序遍历)

    The order of a Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  5. hdu3999-The order of a Tree (二叉树的先序遍历)

    http://acm.hdu.edu.cn/showproblem.php?pid=3999 The order of a Tree Time Limit: 2000/1000 MS (Java/Ot ...

  6. 二叉排序树:HUD3999-The order of a Tree(二叉排序树字典序输出)

    The order of a Tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...

  7. The order of a Tree

    The order of a Tree Problem Description As we know,the shape of a binary search tree is greatly rela ...

  8. [LeetCode] Group Shifted Strings 群组偏移字符串

    Given a string, we can "shift" each of its letter to its successive letter, for example: & ...

  9. POJ No.3617【B008】

    [B007]Best Cow Line[难度B]———————————————————————————————————————————————— [Description    支持原版从我做起!!! ...

  10. Simple Network Management Protocol - SNMP Tutorial

    30.9 Simple Network Management Protocol Network management protocols specify communication between t ...

随机推荐

  1. C语言初级阶段4——数组3——字符数组

    C语言初级阶段4--数组3--字符数组 字符数组的定义:储存字符类型数据的集合 1.注意:如果用字符串给字符数组初始化,那么不需要{},但是要有"". 2.%s :用来输出字符串的 ...

  2. js两个数组对象合并去重

  3. Java中多态相关知识点

    多态 1.多态概述 同一个对象在不同时刻表现出的不同形态 多态的前提和体现: 有继承/实现关系 有方法重写 有父类引用指向子类对象(Animal a = new Cat();) 2.多态中的成员访问特 ...

  4. DP-最大子矩阵

    1768:最大子矩阵 题目描述: 描述已知矩阵的大小定义为矩阵中所有元素的和.给定一个矩阵,你的任务是找到最大的非空(大小至少是1 * 1)子矩阵比如,如下4 * 4的矩阵 0 -2 -7 09 2 ...

  5. 关于 indy Idhttp Post数据抛异常 connection closed Gracefully

    delphi 使用indy -idHttp 控件post 数据时 会报connection closed Gracefully这个异常的问题. 网上找了很多方法最多的就是 修改: MyHttp.Req ...

  6. Scala操作Kakfa API

    如需大数据开发整套视频(hadoop\hive\hbase\flume\sqoop\kafka\zookeeper\presto\spark):请联系QQ:1974983704 由于我使用的是kafk ...

  7. Assert的使用和简单解释

    Assert 的简单使用 Document d = Jsoup.connect("http://www.baidu.com").get(); Assert.notNull(d, & ...

  8. yapi的一些基本操作

    一.yapi能干什么 强大的接口管理平台 提供mock功能 提供测试功能 项目管理功能 插件齐全 二.yapi的权限 项目权限 操作 游客 项目开发者 项目组长 超级管理员 浏览公开项目与接口 √ √ ...

  9. mysql error Code 1441:datetime function: datetime field overflow

    mysql  error Code 1441:datetime function: datetime field overflow 网上找了好久,也没有解决 最后发现有个left join 表,on关 ...

  10. JSON常见用法

    https://blog.csdn.net/weixin_43631296/article/details/105253434