Advertisement
JmihPodvalbniy

Untitled

Dec 1st, 2024
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | Software | 0 0
  1. Дз от 27.11.2024г.
  2.  
  3. 1)
  4. #include <iostream>
  5. #include <string>
  6.  
  7. int main() {
  8.     std::string user_input;
  9.     std::cout << "Введите строку: ";
  10.     std::getline(std::cin, user_input);
  11.  
  12.     user_input.erase(std::remove(user_input.begin(), user_input.end(), ' '), user_input.end());
  13.  
  14.     std::cout << "Строка без пробелов: " << user_input << std::endl;
  15.  
  16.     return 0;
  17. }
  18.  
  19. 2)
  20. #include <iostream>
  21. #include <string>
  22. #include <cctype>
  23.  
  24. int main() {
  25.  std::string user_input;
  26.  std::cout << "Введите строку: ";
  27.  std::getline(std::cin, user_input);
  28.  
  29.  char target_letter = 'a';
  30.  
  31.  int count = 0;
  32.  for (char c : user_input) {
  33.   if (std::tolower(c) == target_letter) {
  34.    ++count;
  35.   }
  36.  }
  37.  
  38.  std::cout << "Количество буквы '" << target_letter << "' в строке: " << count << std::endl;
  39.  
  40.  return 0;
  41. }
  42.  
  43. 3)
  44. #include <iostream>
  45. #include <string>
  46.  
  47. int main() {
  48.  std::string string1, string2;
  49.  std::cout << "Введите первую строку: ";
  50.  std::getline(std::cin, string1);
  51.  std::cout << "Введите вторую строку: ";
  52.  std::getline(std::cin, string2);
  53.  
  54.  std::string result = string1 + " " + string2;
  55.  
  56.  std::cout << "Результат: " << result << std::endl;
  57.  
  58.  return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement