Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- const int max_words = 31;
- const int max_lenght = 6;
- char **words = new char *[max_words];
- for (int i = 0; i < max_words; i++)
- words[i] = new char[max_lenght];
- cout << "Enter the string = ";
- int i_tmp = 0, j_tmp = 0, n_words = 0;
- char symbol = getchar();
- while (symbol != '.')
- {
- if (symbol == ',')
- {
- n_words++;
- words[i_tmp][j_tmp] = '\0';
- i_tmp++;
- j_tmp = 0;
- }
- else
- {
- words[i_tmp][j_tmp] = symbol;
- j_tmp++;
- }
- symbol = getchar();
- }
- words[i_tmp][j_tmp] = '\0';
- n_words++;
- cout << endl << "Words:" << endl;
- for (int i = 0; i < n_words; i++)
- {
- cout << i + 1 << ") ";
- for (int j = 0; words[i][j] != '\0'; j++)
- {
- cout << words[i][j];
- }
- cout << endl;
- }
- cout << endl << "Result:" << endl;
- for (int i = 0; i < n_words; i++)
- {
- bool is_correct = true;
- for (int j = 0; j < i; j++)
- if (tolower(words[j][0]) >= tolower(words[i][0]))
- {
- is_correct = false;
- break;
- }
- if (is_correct)
- {
- for (int j = i + 1; j < n_words; j++)
- if (tolower(words[j][0]) <= tolower(words[i][0]))
- {
- is_correct = false;
- break;
- }
- if (is_correct)
- {
- for (int j = 0; words[i][j] != '\0'; j++)
- cout << words[i][j];
- cout << endl;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement