#include<iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;
void Reverse(char* str, int s, int e)
{
char tmp;
for (;s<e;s++,e--)
{
tmp = str[s];
str[s] = str[e];
str[e] = tmp;
}
}
void move(char *str,int k,int n)//分为两块,转置的思想
{
if (k>0&&n>0)
{
Reverse(str, 0, k - 1);
Reverse(str, k, n - 1);
Reverse(str, 0, n - 1);
printf("%s\n", str);
}
}
int main()
{
char str[25];
int k,n;
while(scanf("%s%d",str,&k)!=EOF)
{
n=strlen(str);
if (k > n)
{
k %= n;
}
move(str,k,n);
}
system("pause");
}循环移位
最新推荐文章于 2024-08-06 17:03:58 发布
485

被折叠的 条评论
为什么被折叠?



