当前位置:网站首页>2000. reverse word prefix
2000. reverse word prefix
2022-07-23 09:12:00 【Mr Gao】
2000. Reverse word prefix
I'll give you a subscript from 0 Starting string word And a character ch . find ch First occurrence of subscript i , reverse word From the subscript 0 Start 、 Until the subscript i end ( Including subscript i ) That part of the character . If word There are no characters in ch , Then no operation is required .
for example , If word = "abcdefd" And ch = "d" , Then you should reverse From the subscript 0 Start 、 Until the subscript 3 end ( Including subscript 3 ). The result string will be "dcbaefd" .
return Result string .
Example 1:
Input :word = “abcdefd”, ch = “d”
Output :“dcbaefd”
explain :“d” The first time it appears in the subscript 3 .
Reverse subscript 0 To the subscript 3( Including subscript 3) This character , The result string is “dcbaefd” .
Example 2:
Input :word = “xyxzxe”, ch = “z”
Output :“zxyxxe”
explain :“z” The first and only occurrence is in the subscript 3 .
Reverse subscript 0 To the subscript 3( Including subscript 3) This character , The result string is “zxyxxe” .
Example 3:
Input :word = “abcd”, ch = “z”
Output :“abcd”
explain :“z” There is no in word in .
No inversion is required , The result string is “abcd” .
The solution code is as follows :
int find_inde(char *s,char ch){
int i=0;
while(s[i]!='\0'){
if(s[i]==ch){
return i;
}
i++;
}
return -1;
}
void reverse(char *s,int index){
int i;
for(i=0;i<index/2+1;i++){
char t=s[index-i];
s[index-i]=s[i];
s[i]=t;;
}
}
char * reversePrefix(char * word, char ch){
int index=find_inde(word,ch);
if(index!=-1){
reverse(word,index);
}
return word;
}
边栏推荐
- 以后面试官问你 为啥不建议使用Select *,请你大声回答他!
- rust allow dead_code
- 软件测试面试思路技巧和方法分享,学到就是赚到
- PostgreSQL and Navicat: the backbone of the database industry
- Day3 POC and exp learning Pikachu brute force cracking with token
- Geely Xingrui: from product technology empowerment to cultural confidence
- go语言中的结构体和组合思想入门示例
- 视频点播中相关分辨率说明
- 【ManageEngine】网络配置管理的6大必备功能
- 十. 实战——云服务器
猜你喜欢

程序员不会 jvm?骨灰级工程师:全等着被淘汰吧!这是必会技能!

Regular expression conversion to corresponding text gadget

软件测试面试思路技巧和方法分享,学到就是赚到

【Try to Hack】AWVS安装和简单使用

Internet Download Manager简直就是下载器中的大杀器

实行自动化网络性能监控的优势
![[concurrent programming] Chapter 2: go deep into the reentrantlock lock lock from the core source code](/img/df/f29eed667c2a7dc02d93ac3f424198.png)
[concurrent programming] Chapter 2: go deep into the reentrantlock lock lock from the core source code

砥砺前行新征程,城链科技狂欢庆典在厦门隆重举行

吉利星瑞:从产品技术赋能到文化自信

Arduino框架下合宙ESP32C3 +1.8“TFT液晶屏通过TFT_eSPI库驱动显示
随机推荐
UGUI源码解析——IMaskable
Compose与RecyclerView结合效果会是怎样的?
Construction of mGRE network
Internet Download Manager简直就是下载器中的大杀器
吉利星瑞:从产品技术赋能到文化自信
2000. 反转单词前缀
flutter 线性布局,填充
The role of include in makefile
2022.7.22-----leetcode.757
【ManageEngine】网络配置管理的6大必备功能
K3s - lightweight kubernetes cluster
UGUI源码解析——MaskableGraphic
input 输入完成时的触发事件
讲一讲HART协议
Anti attack based on conjugate gradient method
setup中的props和context
No requirement document, reject development?
【CANN训练营】学习笔记——Diffusion和GAN对比,Dalle2和Parti
十. 实战——云服务器
IDM下载器免费高质量的Win下载工具无使用限制