*字符串-05. 字符串循环左移

 1 /*
 2  * Main.c
 3  * D5-字符串-05. 字符串循环左移
 4  *  Created on: 2014年8月19日
 5  *      Author: Boomkeeper
 6  ********部分通过*******
 7  */
 8 
 9 #include <stdio.h>
10 
11 int main(void){
12 
13     char str[100]={0};
14     int N=0;//题目中的N
15     int endIndex=99;//字符串的结尾标识符
16 
17     gets(str);
18     scanf("%d",&N);
19     //确定字符串结尾的位置
20     int k;
21     for(k=0;k<100;k++){
22         if(str[k]==''){
23             endIndex=k;
24             break;
25         }
26     }
27     //将N限制在字符串长度范围内
28     while(N>endIndex){
29         N=N%(endIndex+1);
30     }
31     //输出N右边的字符
32     int i;
33     for(i=N;i<endIndex;i++){
34         putchar(str[i]);
35     }
36     //输出N左边的字符
37     int j;
38     for(j=0;j<N;j++){
39         putchar(str[j]);
40     }
41     return 0;
42 }

 

 题目链接:

http://pat.zju.edu.cn/contests/basic-programming/%E5%AD%97%E7%AC%A6%E4%B8%B2-05

.

原文地址:https://www.cnblogs.com/boomkeeper/p/D5.html