当前位置:网站首页>Reverse order and comparison of strings
Reverse order and comparison of strings
2022-06-13 08:10:00 【Stupid little bird learning code】
#include <stdio.h>
#include <string.h>
#include <assert.h>
//1. The first one is
void left_move(char* arr,int k)
{
assert(arr);
int i = 0;
int len = strlen(arr);
for(i=0;i<k;i++)
{
// Left hand one character
// First step
char tmp = *arr;
int j = 0;
for(j=0;j<len-1;j++)
{
*(arr+j) = *(arr+j+1);
}
*(arr+len-1) = tmp;
}
}
//2. The second kind ( Three step inversion )
//abcdef
//bafedc
//cdefab
// String array reverse order function
void reverse(char* left,char* right)
{
assert(left != NULL);
assert(right != NULL);
while(left<right)
{
char tmp = *left;
*left = *right;
*right = tmp;
left++;
right--;
}
}
// The reverse
void left_move_3(char* arr,int k)
{
assert(arr);
int len = strlen(arr);
assert(k<len);
reverse(arr,arr+k-1);// On the left in reverse order
reverse(arr+k,arr+len-1);// On the right in reverse order
reverse(arr,arr+len-1);// The whole in reverse order
}边栏推荐
- 24 | adventure and prediction (III): thread pool in CPU
- Detailed explanation of digital certificate and Ca
- Differences between Merkle DAG and Merkle tree
- Common shell script development specifications
- mysql面试题
- leetcode 咒语和药水的成功对数
- 使用kvm创建三台能通局域网的虚拟机
- 2022年危险化学品经营单位安全管理人员特种作业证考试题库及模拟考试
- EHD ether coin, the hottest dpoc mining project
- [deep learning]: introduction to pytorch to project practice (XII) convolutional neural network: padding and stride
猜你喜欢

2022年电工(初级)考题及模拟考试

Win10系统如何修改桌面路径

CCNP_ BT-MGRE

Tidb source code series: immersive compilation of tidb

CCNP_ Bt-ospf big experiment (1)

Structural analysis of hyperledger fabric (I)

Detailed explanation of digital certificate and Ca

Remote office solution under epidemic situation

Overview of cross chain protocol IBC

1. fabric2.2 comprehensive learning - Preface
随机推荐
母婴用品批发行业使用管理软件提高效率 实现降本增效
Motiko basic syntax in dfinity (ICP) -8
MySQL interview questions
Coalesce() function
【clickhouse专栏】基础数据类型说明
Win10系统如何修改桌面路径
Create a substrate private network
19 | establish data path (bottom): instruction + operation =cpu
Structural analysis of hyperledger fabric (I)
mysql面试题
适合生鲜批发行业的几种精准接单方式
CCNP_ BT static routing
SFTP login and download file script
字符串的逆序与比较
名次的确定
Common shell script development specifications
Selenium foundation API
【Emgu.CV】Emgu. CV. Example\ocr operation reports an error system IO. Filenotfoundexception: "failed to load file or assembly" system.drawing.common "
Give code vitality -- the way to read code neatly
实践出真知--你的字节对齐和堆栈认知可能是错误的