练习8-8 移动字母 (10分)

本题要求编写函数,将输入字符串的前3个字符移到最后。

函数接口定义:

void Shift( char s[] );
 

其中char s[]是用户传入的字符串,题目保证其长度不小于3;函数Shift须将按照要求变换后的字符串仍然存在s[]里。

裁判测试程序样例:

#include <stdio.h>
#include <string.h>

#define MAXS 10

void Shift( char s[] );

void GetString( char s[] ); /* 实现细节在此不表 */

int main()
{
    char s[MAXS];

    GetString(s);
    Shift(s);
    printf("%s
", s);
	
    return 0; 
}

/* 你的代码将被嵌在这里 */
 

输入样例:

abcdef
 

输出样例:

defabc


 1 void Shift( char s[] ){
 2     int n=strlen(s);
 3     char temp;
 4     for(int i=0;i<=2;i++){
 5         temp=s[0];
 6         for(int j=0;j<n-1;j++){
 7             s[j]=s[j+1];
 8         }
 9         s[n-1]=temp;
10     }
11 }
原文地址:https://www.cnblogs.com/samgue/p/13218278.html