当前位置:网站首页>(Sword finger offer version) string inversion
(Sword finger offer version) string inversion
2022-07-21 21:09:00 【liu_ xuixui】
Preface
When it comes to string reverse order, we usually think of , Define two variables that point to the beginning and end of the array left and right, stay left<rigth Under the premise of continuous exchange of array contents . And today we see that the reverse order difficulty of the string will be even higher .
One 、 Topic analysis
Assuming a string "i like beijing." After normal reverse order is ".gnijieb ekil i" The result given in the title is "beijing. like i.
Here is an idea to reverse the normal order of strings to ".gnijieb ekil i", Then reverse each word again to get
To the desired result .
Two 、 Code implementation
#include<stdio.h>
#include<string.h>
void reverse(char* left,char* right) {
while (left<right) {
char temp = *left;
*left = *right;
*right = temp;
left++;
right--;
}
}
int main() {
// Input
char arr[101] = {0};
gets_s(arr);// because scanf When a space is encountered, it will stop reading , So using gets Read in
// The reverse
// The whole is in reverse order
int len = strlen(arr);
reverse(arr,arr+len-1 );
// Single reverse order
char* start = arr;// Define the start position and end position
while (*start) {
char* end = start;
while (*end != ' ' && *end!='\0') {//*end representative end!='\0'
end++;
}
reverse(start, end - 1);// Single reverse order
if (*end!='\0') {
end++;
}
start = end;
}
// Output
printf("%s\n", arr);
return 0;
}
summary
This problem has certain requirements for the knowledge of mutual calls between pointers and string arrays , If you are not familiar with array knowledge, you can only implement it at the array level . If there are deficiencies, please call home for more advice .
边栏推荐
- [file upload bypass] - Secondary rendering
- How to use iterative closest point ICP
- 文件操作上(C语言)
- 【权限提升】提权exp查找思路与利用方法
- Redis (VI) - redis enterprise's actual merchant query cache
- Redis (VII) - encapsulate redis tool classes
- [reverse analysis] basic introduction - simple console login
- Yar framework implements RPC
- 2021-10-23
- PHP basic syntax
猜你喜欢
并发编程(二十九) - 对象的内存布局
Web security -- File Inclusion (local inclusion, remote inclusion)
Uniswap计算过程推演
Compile and run typescript with vscode plug-in coderunner. When the output has Chinese, there is garbled code
【逆向分析】恶意代码静态分析
【逆向分析】C语言指针部分简单学习
【内网渗透】内网渗透红日靶场(vulnstack)二
[intranet penetration] the intranet does not go out of the network, and the machine bounces back to the shell and CS goes online
[intranet penetration] OpenSSL rebound traffic encrypted shell
火山引擎&搜款网:服装批发背后的智慧与“荐”行
随机推荐
PHP基础语法
Volcano engine & SouFun: wisdom and "recommendation" behind clothing wholesale
Interpretation of deflationary dividend currency safemoon
[reverse analysis] basic introduction - search program main function modification program
[permission promotion] MSSQL authorization raising method
Metaforce: my view on the force meta universe, I will teach you to quickly understand the sliding mechanism
并发编程(二十九) - 对象的内存布局
[intranet penetration] OpenSSL rebound traffic encrypted shell
Pawningshop: an implementation of NFT mortgage lending
一天学会MYSQL----学习笔记(一)
PHP环境搭建(推荐宝塔面板)
并发编程(二十七) - JUC之原子类
Rust简短笔记:4种不同的引用变量解答
[intranet penetration] cobaltstrike traffic encryption
PawningShop:一种NFT抵押借贷的实现
Voting implementation of sushitoken
[authority promotion] search ideas and utilization methods of raising rights exp
Redis(五) - Redis企业实战之短信登录
H5 online chat room
【权限提升】MYSQL提权方法