当前位置:网站首页>Huawei interview question: no palindrome string
Huawei interview question: no palindrome string
2022-07-02 14:54:00 【Cool of Si Ku Quan Shu】
subject
【 No palindrome string 】
Definition of palindrome string : Read and reverse the same string
There is already a string that does not contain a palindrome string , The characters of the string are in front of the English letter N individual , And the string does not contain any length greater than or equal to 2 The palindrome of ; Please find the next dictionary order that does not contain palindromes 、 Characters are in front of English letters N individual 、 String with the same length . If it doesn't exist , Please export NO.
Input description :
The first line has an integer :N(1<=N<=26), Indicates that each character range of the string is before N English letters of .
Enter a string in the second line ( Input length <=10000), The input ensures that this string is legal and does not contain a palindrome string .
Output description :
Output the next dictionary order without palindrome string 、 Characters are in front of English letters N individual 、 String with the same length ; If it doesn't exist , Please export ”NO”.
Example 1:
Input :
3
cba
Output :
NO
Example 2:
Input :
4
dbad
Output :
dbcd
Code
#include<iostream>
using namespace std;
int main(){
int n;
cin >> n;
string str;
cin >> str;
int len = str.size();
if(len == 1) {
cout << "NO" << endl;
return 0;
}
for(int i = len - 1; i >= 0; --i){
char next = str[i] + 1;
while(next < 'a'+ n){
int flag = 0;
for(int j = i - 2; j <= i + 2; ++j){
if(j < 0) continue;
if(j >= len) continue;
if(j == i) continue;
if(str[j] == next){
flag = 1;
break;
}
}
if(flag){
next = next + 1;
}else{
str[i] = next;
cout << str << endl;
return 0;
}
}
}
cout << "NO" << endl;
return 0;
}
边栏推荐
- Quick analysis: easy to share the Internet
- PHP linked list creation and traversal
- tmall.product.schema.get( 产品信息获取schema获取 ),淘宝店铺上传商品API接口,淘宝商品发布接口,淘宝商品上传API接口,店铺上传接口,oAuth2.0接口
- 871. 最低加油次数 : 简单优先队列(堆)贪心题
- How does CTO help the business?
- Slashgear shares 2021 life changing technology products, which are somewhat unexpected
- Fundamentals of software testing
- STM32 library function for GPIO initialization
- 数据库连接池和数据源
- jmeter脚本参数化
猜你喜欢

JMeter script parameterization

jmeter脚本参数化

btrace-(字节码)动态跟踪工具
![[development environment] install the visual studio community 2013 development environment (download the installation package of visual studio community 2013 with update 5 version)](/img/7b/2c471c070a3faa981f70136603495a.jpg)
[development environment] install the visual studio community 2013 development environment (download the installation package of visual studio community 2013 with update 5 version)

Full of knowledge points, how to use JMeter to generate encrypted data and write it to the database? Don't collect it quickly

使用mathtype编辑公式,复制粘贴时设置成仅包含mathjax语法的公式

Large top heap, small top heap and heap sequencing

LeetCode 209. 长度最小的子数组

Simple verification code generator for 51 single chip microcomputer experiment

由粒子加速器产生的反中子形成的白洞
随机推荐
【无标题】LeetCode 2321. 拼接数组的最大分数
【题解】Educational Codeforces Round 82
info [email protected] : The platform “win32“ is incompatible with this module.
tmall.product.schema.get( 产品信息获取schema获取 ),淘宝店铺上传商品API接口,淘宝商品发布接口,淘宝商品上传API接口,店铺上传接口,oAuth2.0接口
4. Array pointer and pointer array
Stm32-dac Experiment & high frequency DAC output test
How does CTO help the business?
途家木鸟美团夏日折扣对垒,门槛低就一定香吗?
4、数组指针和指针数组
Thoroughly master prototype__ proto__、 Relationship before constructor (JS prototype, prototype chain)
qml 弹窗框架,可定制
Yolov6 training: various problems encountered in training your dataset
STM32标准固件库函数名(一)
Error: NPM warn config global ` --global`, `--local` are deprecated Use `--location=global` instead.
PTA question bank== > complex four operations, one for one, examination seat number (7-73)
[Space & single cellomics] phase 1: single cell binding space transcriptome research PDAC tumor microenvironment
Implement a server with multi process concurrency
Fabric.js 上划线、中划线(删除线)、下划线
jmeter脚本参数化
Contrôleur pour threejs cube Space Basic Controller + Inertial Control + Flight Control