zoukankan      html  css  js  c++  java
  • 字符串-05. 字符串循环左移

    字符串-05. 字符串循环左移(20)

    时间限制
    400 ms
    内存限制
    65536 kB
    代码长度限制
    8000 B
    判题程序
    Standard
    作者
    白洪欢(浙江大学)

    输入一个字符串和一个非负整数N,要求将字符串循环左移N次。

    输入格式:

    输入在第1行中给出一个不超过100个字符长度的、以回车结束的非空字符串;第2行给出非负整数N。

    输出格式:

    在一行中输出循环左移N次后的字符串。

    输入样例:
    Hello World!
    2
    
    输出样例:
    llo World!He
     1 #include<stdio.h>
     2 #include<math.h>
     3 #include<stdlib.h>
     4 #include<string.h>
     5 int main()
     6 {
     7     char s[110], a[110], b[110];
     8     int n, i, j = 0, temp;
     9     gets(s);
    10     scanf("%d", &n);
    11     n = n % strlen(s);
    12     for(i = n-1; i >= 0; i--)
    13     {
    14         a[j] = s[i];
    15         j++;
    16     }
    17     a[j] = '';
    18     j = 0;
    19     for(i = strlen(s) - 1; i >= n; i--)
    20     {
    21         b[j] = s[i];
    22         j++;
    23     }
    24     b[j] = '';
    25     strcat(a, b);
    26     for(i = strlen(s) - 1; i >= 0; i--)
    27     {
    28         printf("%c", a[i]);
    29     }
    30     return 0;
    31 }
  • 相关阅读:
    BZOJ 3196 二逼平衡树
    BZOJ 4241 历史研究
    Problem 71:Ordered fractions
    矿工安全生产
    Codeforces 771C:Bear and Tree Jumps
    Problem 77:Prime summations
    Problem 69:Totient maximum
    关于Euclid算法
    团体程序设计天梯赛-练习集
    埃蒙的时空航道
  • 原文地址:https://www.cnblogs.com/yomman/p/4241272.html
Copyright © 2011-2022 走看看