AlexAvram

Simulare cluj III.2

Jan 23rd, 2026
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. ///Simulare cluj III.2
  2. #include <iostream>
  3. #include <cstring>
  4. #include <cctype>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     char s[501];
  11.     cin.getline(s, 500);
  12.     ///Citesc tot textul
  13.  
  14.     char *cuvinte[501];
  15.     int nr=0, lungime_max=-1;
  16.  
  17.     char *p=strtok(s, " ");
  18.     while (p!=nullptr)
  19.     {
  20.         cuvinte[++nr]=p;
  21.         if (int(strlen(p))>lungime_max)
  22.             lungime_max=strlen(p);
  23.         p=strtok(nullptr, " ");
  24.     }
  25.     ///memorez toate cuvintele si lungimea maxima intalnita
  26.     int poz_cuv_l[250];
  27.     for (int l=1; l<=lungime_max; ++l)
  28.     {
  29.         int cnt=0;
  30.         for (int i=1; i<=nr; ++i)
  31.             if(strlen(cuvinte[i])==l)
  32.                 poz_cuv_l[++cnt]=i;
  33.         ///memorez pozitiile tuturor cuvintelor de lungime l(l<lungime_max) si numarul lor
  34.         for (int i=1; i<=cnt/2; ++i)
  35.             swap(cuvinte[poz_cuv_l[i]], cuvinte[poz_cuv_l[cnt-i+1]]);
  36.         ///invart cuvintele de lungime l, aflate diametral opus, in vectorul cuvintelor de lungime l
  37.     }
  38.     for (int i=1; i<=nr; ++i)
  39.         cout<<cuvinte[i]<<' ';
  40.     cout<<'\n';
  41.     return 0;
  42. }
  43.  
Add Comment
Please, Sign In to add comment