From: Co-worker Xuan OJ http://xcacm.hfut.edu.cn/problem.php?id=1218
Time limit: 1 Sec memory limit: 2 MB
The title describes a string with a length equal to N, and a string that moves the M-bit to the left.
Input
Two rows per set of data, the first row N m,0<=n<=1000,0<=m<=1500 the second row gives the string, and the string contains only uppercase and lowercase letters.
Output
Outputs the result after the left shift.
Sample input
6 3 Netcan 6 2 Netcan 4 HelloWorld
Sample output
CanNet Tcanne Oworldhell
The crux of the problem is that the length of the left shift of the string may be greater than the length of the string itself, then the implementation program should be able to cycle search, with the% to take the remainder of the simplification.
1#include <iostream>2#include <stdio.h>3#include <string.h>4 using namespacestd;5 intMain ()6 {7 Chard[1550];8 inta,b,i,j,c;9 while(SCANF ("%d%d", &a,&b)! =EOF)Ten { One ACin>>D; - if(b==0) {cout<<d<<Endl;} - Else{ theC=strlen (d); -b=b%A; - for(j=b;j<a;j++) - { +printf"%c", D[j]); - } + for(j=0; j<=b-1; j + +) A { atprintf"%c", D[j]); - } - for(j=a;j<c;j++) - { -printf"%c", D[j]); - } in for(i=0; i<=c;i++) - { tod[i]=0; + } -printf"\ n"); the } * } $ return 0;Panax Notoginseng } - /************************************************************** the problem:1218 + user:2014217052 A language:c++ the Result: Correct + time:34 Ms - memory:1504 KB $ ****************************************************************/
1218: String Shift left