Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<stdio.h>
- #include<string.h>
- char s[256];
- char s2[256];
- char r[256];
- int main() {
- fgets(s, 256, stdin);
- std::cin>>s2;
- int ok = 1;
- int counter = 0;
- char stars[256];
- for (int i = 0; i < strlen(s2); i++) {
- stars[i] = '*';
- }
- while (ok) {
- char *q = strstr(s, s2);
- if (!q) {
- break;
- }
- int dif = q - s;
- // xyabacababa
- // dif = 2
- // r = xy***
- // bacababa
- // dif = 3
- // xy***c***
- // (a)baba
- // dif = 1
- //
- if (!counter) {
- strncat(r, s, dif);
- strcat(r, stars);
- } else if (dif >= strlen(s2) - 1) {
- strncat(r, s + strlen(s2) - 1, dif - strlen(s2) + 1);
- strcat(r, stars);
- } else if (dif < strlen(s2) - 1) {
- strcpy(r + strlen(r) - 3 - dif + strlen(s2), stars);
- }
- strcpy(s, s + dif + 1);
- counter = 1;
- }
- strcat(r, s + strlen(s2) - 1);
- puts(r);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement