Advertisement
MonsterScripter

CodinGame_2023_08_22__13_23_04__n_chars.c

Aug 22nd, 2023
736
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdbool.h>
  5.  
  6. /**
  7.  * Auto-generated code below aims at helping you parse
  8.  * the standard input according to the problem statement.
  9.  **/
  10.  
  11. char *substr(char const *input, size_t start, size_t len) {
  12.     char *ret = malloc(len+1);
  13.     memcpy(ret, input+start, len);
  14.     ret[len]  = '\0';
  15.     return ret;
  16. }
  17.  
  18. int main()
  19. {
  20.     int N;
  21.     scanf("%d", &N); fgetc(stdin);
  22.     char TEXT[1000];
  23.     scanf("%[^\n]", TEXT);
  24.  
  25.     for (int i=0; TEXT[i] != '\0'; i++) {
  26.         char *s = substr(TEXT, i, N);
  27.         printf("%s\n", s);
  28.         if (i+N==strlen(TEXT)) break;
  29.         free(s);
  30.     }
  31.  
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement