当前位置:网站首页>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;
}
边栏推荐
- taobao. logistics. dummy. Send (no logistics delivery processing) interface, Taobao store delivery API interface, Taobao order delivery interface, Taobao R2 interface, Taobao oau2.0 interface
- Understanding of mongodb
- CTO如何帮助业务?
- Yolov6 training: various problems encountered in training your dataset
- Tip: SQL Server blocked the state 'openrowset/opendatasource' of component 'ad hoc distributed queries'
- 检查密码
- 关于网页中的文本选择以及统计选中文本长度
- threejs的控制器 立方體空間 基本控制器+慣性控制+飛行控制
- 【apipost】使用教程
- Delete element (with transition animation)
猜你喜欢

Socket and socket address

Advanced C language (learn malloc & calloc & realloc & free in simple dynamic memory management)

Fabric. JS zoom canvas

Yyds dry goods inventory software encryption lock function

Xilinx Vivado set *.svh as SystemVerilog Header

STM32库函数进行GPIO初始化
![[Space & single cellomics] phase 1: single cell binding space transcriptome research PDAC tumor microenvironment](/img/e1/c8e81570ab78de1e488a611c25ebb9.png)
[Space & single cellomics] phase 1: single cell binding space transcriptome research PDAC tumor microenvironment

Method of creating linked server for cross server data access

【空间&单细胞组学】第1期:单细胞结合空间转录组研究PDAC肿瘤微环境

Fabric.js 橡皮擦的用法(包含恢复功能)
随机推荐
Why can't browsers read JSX?
Introduction to mathjax (web display of mathematical formulas, vector)
Uniapp automated test learning
btrace-(字节码)动态跟踪工具
CTO如何帮助业务?
天猫商品详情接口(APP,H5端)
4. Array pointer and pointer array
Contrôleur pour threejs cube Space Basic Controller + Inertial Control + Flight Control
C#代码审计实战+前置知识
String matching problem
Fabric.js 手动加粗文本iText
PHP linked list creation and traversal
Tujia muniao meituan has a discount match in summer. Will it be fragrant if the threshold is low?
Add vector formula in rich text editor (MathType for TinyMCE, visual addition)
Check password
Database connection pool and data source
threejs的控制器 立方體空間 基本控制器+慣性控制+飛行控制
fatal: unsafe repository is owned by someone else 的解决方法
C语言中的算术运算及相关练习题
STM32 standard firmware library function name memory (II)