Advertisement
monyca98

probl cu sufixe prefixe sir carac 2012 iul

Mar 7th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. using namespace std;
  4. int main()
  5. {
  6.     char s1[20], s2[20];
  7.     cin.get(s1, 19);
  8.     cin.get();
  9.     cin.get(s2, 19);
  10.     char keep[10] = { 0 };
  11.     int count = 0;
  12.     for (int i = 0; i<strlen(s1); i++)
  13.         for (int j = 0; j <strlen(s2); j++)
  14.             if (s1[i] == s2[j])
  15.             {
  16.                 count = 0;
  17.                 if (i + 1 == strlen(s1) && j==0)
  18.                     cout << s1[i] << " ";
  19.                 while (s1[i + 1] == s2[j + 1])
  20.                 {
  21.                     count++; i++; j++;
  22.                 }
  23.                 if (count != 0)
  24.                 {
  25.                     strncpy(keep, s2, count+1);
  26.                     cout << keep << " ";
  27.                     i--; j--;
  28.                 }
  29.  
  30.  
  31.             }
  32.    
  33.     cout << endl << endl;
  34.     system("pause");
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement