Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4.  
  5. using namespace std;
  6.  
  7. void search(char str[][50], int n, int *n1, char str1[][50], int num[])
  8. {
  9. int i;
  10. char *s,*s1;
  11. *n1=0;
  12. for (i=0; i<n; i++)
  13. {
  14. s = str[i];
  15. while (*s)
  16. if (*s == '[')
  17. {
  18. while (*s && (*s == '[' || *s == ']'))
  19. {
  20. if (*s == '[')
  21. s1 = s;
  22. s++;
  23. }
  24. while (*s && (*s != '[' && *s != ']'))
  25. s++;
  26. if (*s == ']')
  27. {
  28. num[*n1]=i;
  29. strncpy(str1[*n1],s1,s-s1);
  30. str1[*n1][s-s1]='\0';
  31. (*n1)++;
  32. }
  33. }
  34. else
  35. s++;
  36. }
  37. }
  38.  
  39. int find (char str1[][50], int n1)
  40. {
  41. int i, i1=-1, maxi=0;
  42. char *s, *s1;
  43. for (i=0; i<n1; i++)
  44. {
  45. s = str1[i];
  46. while (*s)
  47. if (!isalpha(*s))
  48. {
  49. s1 = s;
  50. while(*s && !isalpha(*s))
  51. s++;
  52. if (s - s1 > maxi)
  53. {
  54. maxi = s - s1;
  55. i1 = i;
  56. }
  57. }
  58. else
  59. s++;
  60. }
  61. return i1;
  62. }
  63.  
  64. bool vstavochka(char *s)
  65. {
  66. bool flag = false;
  67. char *t;
  68. while (*s)
  69. if (*s == '1')
  70. {
  71. flag = true;
  72. t = s + strlen(s);
  73. while (t >= s)
  74. *(t+1)=*t,t--;
  75. *s = '*';
  76. s = s+2;
  77. }
  78. else
  79. s++;
  80. return flag;
  81. }
  82.  
  83. int main()
  84. {
  85. char str[20][50], str1[40][50];
  86. int l1=0, l2, i, i1, nom[40];
  87. puts("Enter array of strings");
  88. while(l1 < 20 && *gets(str[l1]))
  89. l1++;
  90. if(!l1)
  91. puts("Empty array!");
  92. else
  93. {
  94. search(str,l1,&l2,str1,nom);
  95. if(!l2)
  96. {
  97. puts("No substrings");
  98. }
  99. else
  100. {
  101. puts("Substrings found:");
  102. for(i=0;i<l2;i++)
  103. puts(str1[i]);
  104. i1=find(str1,l2);
  105. if(i1==-1)
  106. {
  107. puts("No \'1\' in substrings");
  108. }
  109. else
  110. {
  111. puts("Substring found:");
  112. puts(str1[i1]);
  113. puts(str[nom[i1]]);
  114. puts("Will be changed");
  115. if(vstavochka(str[nom[i1]]))
  116. {
  117. puts("Changed string");
  118. puts(str[nom[i1]]);
  119. }
  120. else
  121. puts("String was not changed");
  122. }
  123. }
  124. }
  125. return 0;
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement