Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. #define forn(i, n)  for(unsigned int i = 0; i < n; i++)
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6. int sol0() {
  7.     char sh[1000];
  8.     scanf("%s\n", sh);
  9.     char str[1000];
  10.     fgets(str, 1000, stdin);
  11.     unsigned int d['z' + 1];
  12.     forn(i, 'z' + 1)
  13.         d[i] = strlen(sh);
  14.     forn(i, strlen(sh) - 1)
  15.     {
  16.         d[sh[i]] = strlen(sh) - i - 1;
  17.     }
  18.     unsigned int k = strlen(sh) - 1;
  19.     while (k < strlen(str))
  20.     {
  21.             unsigned int y = strlen(sh), j = 1;
  22.             if (!(sh[y - 1] == str[k]))
  23.             {
  24.                 printf("%d ", k + 1);
  25.                 k += d[str[k]];
  26.             }
  27.             else {
  28.                 while (j <= y && sh[y - j] == str[k - j + 1])
  29.                 {
  30.                     printf("%d ", k - j + 2);
  31.                     j++;
  32.                 }
  33.                 if (j <= y)
  34.                 {
  35.                     printf("%d ", k - j + 2);
  36.                 }
  37.                 k += d[str[k]];
  38.             }
  39.     }
  40.     return 0;
  41. }
  42.  
  43. int main() {
  44.     sol0();
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement