当前位置:网站首页>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
}
边栏推荐
- MySQL table partitioning
- v-for生成的子组件列表删除第n行出现数据错乱问题
- Import the robot model built by SolidWorks into ROS
- CCNP_ Bt- Reissue
- 字符串的逆序与比较
- [pytorch] pytorch0.4.0 installation tutorial and GPU configuration collection (including test code)
- redis面试题
- 【PYTORCH】RuntimeError: torch. cuda. FloatTensor is not enabled.
- mysql面试题
- 26 | superscalar and VLIW: how to make the CPU throughput exceed 1
猜你喜欢
1. fabric2.2 comprehensive learning - Preface
将solidworks建的机器人模型导入到ros中
Win10系统如何修改桌面路径
C盘爆满?简单几招教你释放、清理C盘几十G空间,最有效的C盘清理方法
es6删除对象的某个属性
21 | pipeline oriented instruction design (Part 2): How did Pentium 4 fail?
ERP basic data Huaxia
Dfinity (ICP) basic development tutorial-5
CCNP_ BT-MGRE
BD新标签页(BdTab)插件如何登入?
随机推荐
DATE_ SUB()
Practice makes sense -- your byte alignment and stack cognition may be wrong
MySQL table partitioning
set实现名单查找与排除
使用kvm创建三台能通局域网的虚拟机
有什么好的管理软件来解决茶叶批发商面临的难题
Create a substrate private network
批发商为什么要使用订单系统
【博弈论-完全信息静态博弈】 Nash均衡
Common shell script development specifications
Cosmos Starport installation and startup
18 | establish data path (middle): instruction + operation =cpu
Get properties of class
MySQL summary
20 | pipeline oriented instruction design (Part 1): Modern CPU with multi-purpose
基于paddlepaddle的新冠肺炎识别
ES6 deleting an attribute of an object
钉钉小程序如何隐藏tab
2022年电工(初级)考题及模拟考试
BD新标签页(BdTab)插件如何登入?