Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. char s[256], v[101][30], *p, voc[] = "aeiouAEIOU", t[30];
  9. int n = 0, i, j, a[101] = {0}, nr = 0, aux;
  10.  
  11. cin.getline(s, 256);
  12.  
  13. p = strtok(s , " ");
  14.  
  15. while(p != NULL)
  16. {
  17. n++;
  18. strcpy(v[n], p);
  19.  
  20. for(i = 0; i < strlen(p); i++)
  21. if(strchr(voc, p[i]))
  22. nr++;
  23.  
  24. a[n] = nr;
  25. nr = 0;
  26.  
  27. p = strtok(NULL, " ");
  28. }
  29.  
  30. for(i = 1; i < n; i++)
  31. for(j = i + 1; j <= n; j++)
  32. {
  33. if(a[i] < a[j])
  34. {
  35. aux = a[j];
  36. a[j] = a[i];
  37. a[i] = aux;
  38.  
  39. strcpy(t, v[i]);
  40. strcpy(v[i], v[j]);
  41. strcpy(v[j] , t);
  42. }
  43. else if(a[i] == a[j])
  44. if(strlen(v[i]) < strlen(v[j]))
  45. {
  46. strcpy(t, v[i]);
  47. strcpy(v[i], v[j]);
  48. strcpy(v[j] , t);
  49. }
  50. else if(strlen(v[i]) == strlen(v[j]) && strcmp(v[i], v[j]) == 1)
  51. {
  52. strcpy(t, v[i]);
  53. strcpy(v[i], v[j]);
  54. strcpy(v[j] , t);
  55. }
  56. }
  57.  
  58. for(i = 1; i <= n; i++)
  59. cout << v[i] << '\n';
  60.  
  61. return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement