#include<iostream>
#include<string>
using namespace std;
void shunxu(char t[80], char a[80], int m)
{
int i, j;
for (i = 0; i < m; i++)
t[i] = a[i];//1-m的字符放入数组t中
for (i = 0; i < (strlen(a)) - m; i++) /*m以后的字符前移*/
a[i] = a[i + m];
for (j = 0; j < m; j++)
{
a[i] = t[j];//t数组中的值放在数组a后面
i++;
}
a[i] = '\0';/*添加结束标志*/
}
int main(void)
{
char t[80], a[80]="ABCDEFGHIJ";
int m;
cout << "原始数组为:" << endl;
puts(a);
cout << "请输入平移量" << endl;
cin >> m;
shunxu(t,a, m);
cout << "移动后数组为:" << endl;
puts(t);
return 0;
}
我也不懂为什么有一堆的烫,应该怎么改
#include <bits/stdc++.h>
void func(char arr[10], int m)
{
char res[10];
for(int i = 0; i < 10; i++) res[(i+m)%10] = arr[i];
for(int i = 0; i < 10; i++) arr[i] = res[i];
}
int main()
{
char arr[10] = "ABCDEFGHI";
func(arr, 4);
for(int i = 0; i < 10; i++) std::cout << arr[i];
return 0;
}
|