NC232091. Lexicographic Order
描述
输入描述
The first line of input contains two integers --- the length of and the length limit of .
The second line contains a string with length of , as the string Nana7mi has.
输出描述
Output a string with length not exceed and containing only lowercase characters in a line.
示例1
输入:
3 4 ybb
输出:
ybaz
C 解法, 执行用时: 7ms, 内存消耗: 3228K, 提交时间: 2021-12-18 16:59:02
#include<stdio.h> char a[1000005]; char b[1000005]; int main(){ int n,m,i; scanf("%d %d",&n,&m); scanf("%s",a); for(i=0;i<n-1;i++){ b[i]=a[i]; } if(a[i]!='a'){ b[i]=a[i]-1; for(i=i+1;i<m;i++){ b[i]='z'; } } printf("%s",b); return 0; }
C++ 解法, 执行用时: 27ms, 内存消耗: 2496K, 提交时间: 2021-12-19 16:03:46
#include<bits/stdc++.h> using namespace std; int n,m; string s; int main () { cin>>n>>m>>s; if (s.back()=='a') s.pop_back(); else { s.back()--; while (s.size()<m) s.push_back('z'); } cout<<s; }
pypy3 解法, 执行用时: 96ms, 内存消耗: 27612K, 提交时间: 2022-11-03 15:04:04
n,m=map(int,input().split()) s=input() if s[n-1]=="a": print(s[:-1]) else: print(s[:-1]+chr(ord(s[n-1])-1)+"z"*(m-n))