Advertisement
Sanlover

Untitled

Dec 22nd, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. const int max_words = 31;
  6. const int max_lenght = 6;
  7.  
  8. char **words = new char *[max_words];
  9. for (int i = 0; i < max_words; i++)
  10. words[i] = new char[max_lenght];
  11. cout << "Enter the string = ";
  12.  
  13. int i_tmp = 0, j_tmp = 0, n_words = 0;
  14. char symbol = getchar();
  15. while (symbol != '.')
  16. {
  17. if (symbol == ',')
  18. {
  19. n_words++;
  20. words[i_tmp][j_tmp] = '\0';
  21. i_tmp++;
  22. j_tmp = 0;
  23. }
  24. else
  25. {
  26. words[i_tmp][j_tmp] = symbol;
  27. j_tmp++;
  28. }
  29. symbol = getchar();
  30. }
  31. words[i_tmp][j_tmp] = '\0';
  32. n_words++;
  33.  
  34. cout << endl << "Words:" << endl;
  35. for (int i = 0; i < n_words; i++)
  36. {
  37. cout << i + 1 << ") ";
  38. for (int j = 0; words[i][j] != '\0'; j++)
  39. {
  40. cout << words[i][j];
  41. }
  42. cout << endl;
  43. }
  44.  
  45. cout << endl << "Result:" << endl;
  46. for (int i = 0; i < n_words; i++)
  47. {
  48. bool is_correct = true;
  49. for (int j = 0; j < i; j++)
  50. if (tolower(words[j][0]) >= tolower(words[i][0]))
  51. {
  52. is_correct = false;
  53. break;
  54. }
  55. if (is_correct)
  56. {
  57. for (int j = i + 1; j < n_words; j++)
  58. if (tolower(words[j][0]) <= tolower(words[i][0]))
  59. {
  60. is_correct = false;
  61. break;
  62. }
  63. if (is_correct)
  64. {
  65. for (int j = 0; words[i][j] != '\0'; j++)
  66. cout << words[i][j];
  67. cout << endl;
  68. }
  69. }
  70. }
  71.  
  72. return 0;
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement