Advertisement
Guest User

Untitled

a guest
Jun 29th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<string.h>
  4.  
  5. char s[256];
  6. char s2[256];
  7. char r[256];
  8.  
  9. int main() {
  10.  
  11. fgets(s, 256, stdin);
  12.  
  13. std::cin>>s2;
  14.  
  15. int ok = 1;
  16.  
  17. int counter = 0;
  18.  
  19. char stars[256];
  20. for (int i = 0; i < strlen(s2); i++) {
  21. stars[i] = '*';
  22. }
  23.  
  24. while (ok) {
  25.  
  26. char *q = strstr(s, s2);
  27.  
  28. if (!q) {
  29. break;
  30. }
  31.  
  32. int dif = q - s;
  33.  
  34. // xyabacababa
  35. // dif = 2
  36. // r = xy***
  37. // bacababa
  38. // dif = 3
  39. // xy***c***
  40. // (a)baba
  41. // dif = 1
  42. //
  43.  
  44. if (!counter) {
  45. strncat(r, s, dif);
  46. strcat(r, stars);
  47. } else if (dif >= strlen(s2) - 1) {
  48. strncat(r, s + strlen(s2) - 1, dif - strlen(s2) + 1);
  49. strcat(r, stars);
  50. } else if (dif < strlen(s2) - 1) {
  51. strcpy(r + strlen(r) - 3 - dif + strlen(s2), stars);
  52. }
  53.  
  54. strcpy(s, s + dif + 1);
  55.  
  56. counter = 1;
  57.  
  58. }
  59.  
  60. strcat(r, s + strlen(s2) - 1);
  61.  
  62. puts(r);
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement