Username77177

Dahl-Programming-Lab12-16

Apr 3rd, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4. // Приветствие
  5. // Ввод слов
  6. // Разбиение слов на массив, где пробел переключает ячейку
  7. // Выбор пятибуквенных слов
  8. // Сортировка пятибуквенных слов
  9.  
  10. using namespace std;
  11.  
  12. int main(int argc, char *argv[])
  13. {
  14. //Variables
  15. //
  16.  
  17.  
  18. string user_input; // Строка, куда пользователь введёт слова
  19. string words[10]; // Первые 10 слов
  20. int start_index = 0; // Индекс для отсчёта
  21.  
  22. cout << "Привет! Введите несколько слов до 10 (желательно 5-ти буквенных, но не обязательно)" << endl;
  23. getline(cin,user_input);
  24. for (auto i : user_input) {
  25. if (i != ' ') {
  26. if (start_index < 10)
  27. {
  28. words[start_index] += i;
  29. }
  30. }
  31. else {
  32. start_index++;
  33. }
  34. }
  35. cout << "Слова, которые будут сортироваться: ";
  36. for (int i = 0; i < 10; i++) {
  37. if (words[i] != "")
  38. {
  39. if (words[i].size() == 10)
  40. {
  41. cout << words[i] << " ";
  42. }
  43. }
  44. }
  45. sort(words, words + 10); // Сортировка
  46. cout << "\nОтсортированный массив: \n";
  47. for (int i = 0; i < 10; i++)
  48. {
  49. if (words[i].size() == 10 )
  50. {
  51. cout << words[i] << " ";
  52. }
  53. }
  54. cout << endl;
  55.  
  56. //Задача 2. Задано слово произвольной длины. Удалить из него последний символ.
  57. cout << "Введите слово: " << endl;
  58. char newword[256];
  59. cin >> newword;
  60. cout << newword;
  61. for (auto i : newword) {
  62. cout << i << endl;
  63. }
  64. return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment