Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///Simulare cluj III.2
- #include <iostream>
- #include <cstring>
- #include <cctype>
- using namespace std;
- int main()
- {
- char s[501];
- cin.getline(s, 500);
- ///Citesc tot textul
- char *cuvinte[501];
- int nr=0, lungime_max=-1;
- char *p=strtok(s, " ");
- while (p!=nullptr)
- {
- cuvinte[++nr]=p;
- if (int(strlen(p))>lungime_max)
- lungime_max=strlen(p);
- p=strtok(nullptr, " ");
- }
- ///memorez toate cuvintele si lungimea maxima intalnita
- int poz_cuv_l[250];
- for (int l=1; l<=lungime_max; ++l)
- {
- int cnt=0;
- for (int i=1; i<=nr; ++i)
- if(strlen(cuvinte[i])==l)
- poz_cuv_l[++cnt]=i;
- ///memorez pozitiile tuturor cuvintelor de lungime l(l<lungime_max) si numarul lor
- for (int i=1; i<=cnt/2; ++i)
- swap(cuvinte[poz_cuv_l[i]], cuvinte[poz_cuv_l[cnt-i+1]]);
- ///invart cuvintele de lungime l, aflate diametral opus, in vectorul cuvintelor de lungime l
- }
- for (int i=1; i<=nr; ++i)
- cout<<cuvinte[i]<<' ';
- cout<<'\n';
- return 0;
- }
Add Comment
Please, Sign In to add comment