7-31
輸入一個字符串和一個非負整數N,要求將字符串循環左移N次。
輸入格式:
輸入在第1行中給出一個不超過100個字符長度的、以回車結束的非空字符串;第2行給出非負整數N。
輸出格式:
在一行中輸出循環左移N次后的字符串。
輸入樣例:
Hello World!
2
輸出樣例:
llo World!He
AC代碼
#include<stdio.h>
#define max 105
int main(){
char s;//指單獨一個字符
char t[max];//創建一個字符數組
int i = 0, count = 0, flag = 0;
while ((s=getchar()) != '\n') {//getchar每次從標准輸入讀入一個字符 ,標准輸入會有'\n'???
t[i++] = s;
count++;
}
int N;
scanf("%d",&N);
if(N > count) {
N %= count;
} //這里有個測試點
for(int i=N;i<count;i++){
printf("%c",t[i]);
}
for(int i=0;i<N;i++){
printf("%c",t[i]);
}
return 0;
}