Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- using namespace std;
- void search(char str[][50], int n, int *n1, char str1[][50], int num[])
- {
- int i;
- char *s,*s1;
- *n1=0;
- for (i=0; i<n; i++)
- {
- s = str[i];
- while (*s)
- if (*s == '[')
- {
- while (*s && (*s == '[' || *s == ']'))
- {
- if (*s == '[')
- s1 = s;
- s++;
- }
- while (*s && (*s != '[' && *s != ']'))
- s++;
- if (*s == ']')
- {
- num[*n1]=i;
- strncpy(str1[*n1],s1,s-s1);
- str1[*n1][s-s1]='\0';
- (*n1)++;
- }
- }
- else
- s++;
- }
- }
- int find (char str1[][50], int n1)
- {
- int i, i1=-1, maxi=0;
- char *s, *s1;
- for (i=0; i<n1; i++)
- {
- s = str1[i];
- while (*s)
- if (!isalpha(*s))
- {
- s1 = s;
- while(*s && !isalpha(*s))
- s++;
- if (s - s1 > maxi)
- {
- maxi = s - s1;
- i1 = i;
- }
- }
- else
- s++;
- }
- return i1;
- }
- bool vstavochka(char *s)
- {
- bool flag = false;
- char *t;
- while (*s)
- if (*s == '1')
- {
- flag = true;
- t = s + strlen(s);
- while (t >= s)
- *(t+1)=*t,t--;
- *s = '*';
- s = s+2;
- }
- else
- s++;
- return flag;
- }
- int main()
- {
- char str[20][50], str1[40][50];
- int l1=0, l2, i, i1, nom[40];
- puts("Enter array of strings");
- while(l1 < 20 && *gets(str[l1]))
- l1++;
- if(!l1)
- puts("Empty array!");
- else
- {
- search(str,l1,&l2,str1,nom);
- if(!l2)
- {
- puts("No substrings");
- }
- else
- {
- puts("Substrings found:");
- for(i=0;i<l2;i++)
- puts(str1[i]);
- i1=find(str1,l2);
- if(i1==-1)
- {
- puts("No \'1\' in substrings");
- }
- else
- {
- puts("Substring found:");
- puts(str1[i1]);
- puts(str[nom[i1]]);
- puts("Will be changed");
- if(vstavochka(str[nom[i1]]))
- {
- puts("Changed string");
- puts(str[nom[i1]]);
- }
- else
- puts("String was not changed");
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement