当前位置:网站首页>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;
}
边栏推荐
- STM32标准固件库函数名(一)
- MQ教程 | Exchange(交换机)
- [development environment] StarUML tool (download software | StarUML installation | StarUML creation project)
- 华为面试题: 没有回文串
- Borui data integrated intelligent observable platform was selected into the "Yunyuan production catalogue" of China Academy of communications in 2022
- Delete element (with transition animation)
- 电脑怎么设置扬声器播放麦克风的声音
- JMeter script parameterization
- Fabric. Usage of JS eraser (including recovery function)
- 1. Editing weapon VIM
猜你喜欢

##51单片机实验之简易验证码发生器

Yyds dry goods inventory software encryption lock function

Fabric.js 缩放画布

Implement a server with multi process concurrency

微信小程序使用towxml显示公式

Reuse and distribution

Borui data integrated intelligent observable platform was selected into the "Yunyuan production catalogue" of China Academy of communications in 2022

Large top heap, small top heap and heap sequencing

LeetCode 2320. 统计放置房子的方式数

途家木鸟美团夏日折扣对垒,门槛低就一定香吗?
随机推荐
Convolutional neural network (Introduction)
Simple verification code generator for 51 single chip microcomputer experiment
LeetCode 209. 长度最小的子数组
Large top heap, small top heap and heap sequencing
[QNX Hypervisor 2.2用户手册]6.3 Guest与外部之间通信
LeetCode_滑动窗口_中等_395.至少有 K 个重复字符的最长子串
Uniapp automated test learning
Reuse and distribution
taobao.trade.memo.add( 对一笔交易添加备注 )接口,淘宝店铺插旗接口,淘宝订单插旗API接口,oAuth2.0接口
Implement a server with multi process concurrency
info [email protected] : The platform “win32“ is incompatible with this module.
PTA question bank== > complex four operations, one for one, examination seat number (7-73)
[development environment] StarUML tool (download software | StarUML installation | StarUML creation project)
使用mathtype编辑公式,复制粘贴时设置成仅包含mathjax语法的公式
fatal: unsafe repository is owned by someone else 的解决方法
Database connection pool and data source
Fabric.js 橡皮擦的用法(包含恢复功能)
Bit by bit of OpenCV calling USB camera
Advanced C language (learn malloc & calloc & realloc & free in simple dynamic memory management)
Advanced usage of C language -- function pointer: callback function; Conversion table