Enter a string and a non-negative integer N, and the string must be shifted left n times.
Input Format:
The input row contains a non-empty string of no more than 1st characters ending with a carriage return. The input row contains a non-negative integer n.
Output Format:
Output the string after N cycles are shifted left in one row.
Input example:
Hello World!2
Output example:
llo World!He
# Include <stdio. h>
# Include <string. h>
Int main () {char s [101], S2 [101];
Int N;
Gets (s );
Char * P = s;
Scanf ("% d", & N );
N = n % strlen (s); // left shift length judgment
P = P + N;
Strcpy (S2, P); // copy the flag to S2 on the right
// S2 [N] = '\ 0 ';
* P = '\ 0'; // s to the string on the left of the flag
// Strcpy (S, P );
Strcat (S2, S); // The Connection operation is completed and moved left;
Puts (S2 );
Return 0;
}
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(void){
const int length_of_array = 101; // Define the array Length
char sentence[length_of_array];
char *temporary = (char*)malloc(sizeof(char)*length_of_array); // Temporary memory space
int shift; // Offset
gets(sentence);
scanf("%d",&shift);
int length_of_sentence = strlen(sentence); // Obtain the length of the input data
if ( shift > length_of_sentence){ // When the processing offset is greater than the Data Length
shift = shift % length_of_sentence;
}
char *located_address = sentence + shift; // This address is the address after shift offset relative to the original address"
strcpy(temporary,located_address); // Copy all the contents of the Offset address to the temporary container.
*located_address = ‘\0‘; // Change the data corresponding to the offset address to '\ 0' for use below
strcat(temporary,sentence); // The data content of the original address is directly appended to the temporary space.
printf("%s",temporary); free(temporary);
return 0;
}