Lexicographic Order
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的更多相关文章
- 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 ...
- 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 ...
- <hdu - 3999> The order of a Tree 水题 之 二叉搜索的数的先序输出
这里是杭电hdu上的链接:http://acm.hdu.edu.cn/showproblem.php?pid=3999 Problem Description: As we know,the sha ...
- 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 ...
- 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 ...
- 二叉排序树: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) ...
- 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 ...
- [LeetCode] Group Shifted Strings 群组偏移字符串
Given a string, we can "shift" each of its letter to its successive letter, for example: & ...
- POJ No.3617【B008】
[B007]Best Cow Line[难度B]———————————————————————————————————————————————— [Description 支持原版从我做起!!! ...
- Simple Network Management Protocol - SNMP Tutorial
30.9 Simple Network Management Protocol Network management protocols specify communication between t ...
随机推荐
- cmd 下运行pyhon文件.py
第一步: wind+R打开[运行],输入cmd,点击确定 第二步: ①输入:[cd]指定pyhon文件目录 ② cd C:\Users\pc\Desktop\test ③在指定目录下输入pyhon文件 ...
- python 猜数字
方法一 import randomif __name__ == '__main__': yourname = input("你好! 你的名字是什么?\n"); prin ...
- git push 报错error: remote unpack failed: error Short read of block
1.解决办法:找管理代码的人给你开权限. 2如果你的push的命令写错的话,也是会出现远端拒绝的提示,所以记得检查自己的push 命令是否正确 另一种明显的权限拒绝的例子: 英语学习:to push ...
- 面试-JVM
1.java内存模型 / java运行时数据区模型? 元空间属于本地内存 而非JVM内存 内存模型 程序计数器 1.作为字节码的行号指示器,字节码解释器通过程序计数器来确定下一步要执行的字节码指令,比 ...
- flask动态csv接口——编码问题
@xxx_blueprint.route("/file", methods=["GET"]) def group_trend(): def generate() ...
- clion环境配置
如果是学生:直接使用学校的邮箱,可以直接注册使用 环境配置:下载:https://sourceforge.net/projects/mingw-w64/
- Switch问题
package com.company;public class Main { public static void main(String[] args) { Income[] incomes = ...
- 如何加快打开网页的速度------通过调节“QoS数据包计划程序”的“限制可保留宽带”实现&如何解决win10可能找不到gpedit.msc的问题
参考:http://www.windowszj.com/news/win10/42119.html http://www.docin.com/p-1510367352.html(QoS数据包计划程序有 ...
- 发布订阅者模式 -- 简单的PubSub
/** * 发布订阅者模式 * **/interface handle { [propName: string]: Function[]}class PubSub { private handles: ...
- Android笔记--在活动之间传递消息
显式Intent和隐式Intent Intent--各个组件信息沟通的桥梁 组成部分: 显式Intent:--精确匹配 具体实现: 1.在Intent的构造函数中指定 2.调用意图对象的setClas ...