6-7 移動字母 (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\n", s); return 0; } /* 你的代碼將被嵌在這里 */
輸入樣例:
abcdef
輸出樣例:
defabc
void Shift( char s[] )
{
int i;
char temp;
int j;
for(i=0;i<3;i++)
{
temp=s[0];
for(j=1;j<strlen(s);j++)
{
s[j-1]=s[j];
}
s[j-1]=temp;
}
}