把数组中基数位的数移到数组后半部_并保持相对位置不变

本文介绍了一个C++程序,该程序能够将数组中的字符按奇数位和偶数位重新排列,同时保持其相对位置不变。例如,对于字符串'a1b2c3d4e5f6',程序会将其调整为'abcdef123456'的形式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


http://blog.youkuaiyun.com/hackbuteer1/article/details/8035261
// 把数组中基数位的数移到数组后半部_并保持相对位置不变.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "string.h"

//a1b2c3d4e5->abcde12345



void swap(char *Array, int idx1, int idx2)
{
	char tmp = Array[idx1];
	Array[idx1] = Array[idx2];
	Array[idx2] = tmp;
}

void swapArray(char *Array, int startIdx, int len)
{
	int targetIdx = startIdx+len;
	int loop = startIdx;

	while (targetIdx > startIdx)
	{
		swap(Array, targetIdx-1, targetIdx);
		targetIdx--;
	}
}
、、http://blog.youkuaiyun.com/hackbuteer1/article/details/8035261
void modifyArray(char *Array, int len)
{
	int switchTimes = len/2 - 1;

	for (int tryIdx = 1; tryIdx <= switchTimes; tryIdx++)
	{
		swapArray(Array, tryIdx, tryIdx); 
	}
}


int _tmain(int argc, _TCHAR* argv[])
{
    
	char A[] = "a1b2c3d4e5f6";

	modifyArray(A, 12);


	return 0;
}



http://blog.youkuaiyun.com/hackbuteer1/article/details/8035261

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值