Advertisement
hopingsteam

Untitled

May 11th, 2020
1,271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include    <iostream>
  2. #include    <cstring>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     char vectorCuv[100][101];
  9.     int totalCuv = 0;
  10.  
  11.     char text[101]; // testez validez utilizez date corecte acum
  12.     cin.getline(text, 101);
  13.  
  14.     char *cuvant = strtok(text, " ");
  15.     while(cuvant != NULL)
  16.     {
  17.         strcpy(vectorCuv[totalCuv], cuvant);
  18.         totalCuv++;
  19.  
  20.         cuvant = strtok(NULL, " ");
  21.     }
  22.  
  23.     int inserari = 0;
  24.     for(int i = 0; i < totalCuv - 1; i++)
  25.     {
  26.         char uc1 = vectorCuv[i][strlen(vectorCuv[i]) - 1];
  27.         char uc2 = vectorCuv[i + 1][strlen(vectorCuv[i + 1]) - 1];
  28.         if(uc1 == uc2)
  29.         {
  30.             for(int j = totalCuv; j > i; j--)
  31.                 strcpy(vectorCuv[j], vectorCuv[j - 1]);
  32.             strcpy(vectorCuv[i + 1], "succes");
  33.             totalCuv++;
  34.             inserari++;
  35.         }
  36.     }
  37.  
  38.     strcpy(text, "");
  39.     for(int i = 0; i < totalCuv - 1; i++)
  40.     {
  41.         strcat(text, vectorCuv[i]);
  42.         strcat(text, " ");
  43.     }
  44.  
  45.     if(inserari != 0)
  46.         cout << text;
  47.     else
  48.         cout << "nu exista";
  49.    
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement