Advertisement
a53

VocSortDesc

a53
Jan 20th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. int nr_voc(char s[]) /// Numara cate vocale are un sir
  6. {
  7. int nrv=0;
  8. for(int i=0;i<(int)strlen(s);++i)
  9. if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u'||s[i]=='A'||s[i]=='E'||s[i]=='I'||s[i]=='O'||s[i]=='U')
  10. ++nrv;
  11. return nrv;
  12. }
  13.  
  14. int main()
  15. {
  16. char a[256],cuv[256][256],*p,separator[]=" ";
  17. cin.get(a,256);
  18. p=a;
  19. p=strtok(p,separator);
  20. int nr=0;
  21. while(p) /// Separam cuvintele
  22. strcpy(cuv[++nr],p),p=strtok(NULL,separator);
  23. int F[nr+1]; /// retine numarul de vocale
  24. for(int i=1;i<=nr;++i) /// Memoram numarul de vocalele pentru fiecare cuvant
  25. F[i]=nr_voc(cuv[i]);
  26. for(int i=1;i<nr;++i) /// Sortam
  27. for(int j=i+1;j<=nr;++j)
  28. if(F[i]<=F[j])
  29. {
  30. if(F[i]==F[j]) /// Acelasi numar de vocale
  31. {
  32. if(strlen(cuv[i])<=strlen(cuv[j]))
  33. {
  34. if((strlen(cuv[i])==strlen(cuv[j]))) /// Cuvintele au aceeasi lungime
  35. {
  36. if(strcmp(cuv[i],cuv[j])!=-1) /// Daca cuv[i]>=cuv[j]
  37. swap(F[i],F[j]),swap(cuv[i],cuv[j]);
  38. }
  39. else /// lungimea cuv[i] < lungimea cuv[j]
  40. swap(F[i],F[j]),swap(cuv[i],cuv[j]);
  41. }
  42. }
  43. else /// F[i]<F[j]
  44. swap(F[i],F[j]),swap(cuv[i],cuv[j]);
  45. }
  46. for(int i=1;i<=nr;++i)
  47. cout<<cuv[i]<<'\n';
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement