Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <set>
- // Функция для удаления знаков препинания из слова
- std::string removePunctuation(const std::string& word) {
- std::string result;
- for (char c : word) {
- if (isalnum(c) || c == '-') {
- result += c;
- }
- }
- return result;
- }
- int main() {
- std::string input;
- // Ввод строки
- std::cout << "Введите строку: ";
- std::getline(std::cin, input);
- // Подсчет количества слов
- std::string word;
- int wordCount = 0;
- for (size_t i = 0; i < input.size(); ++i) {
- if (isalnum(input[i]) || input[i] == '-') {
- word += input[i];
- }
- else if (!word.empty()) {
- wordCount++;
- word.clear();
- }
- }
- if (!word.empty()) {
- wordCount++;
- }
- std::cout << "Количество слов: " << wordCount << std::endl;
- // Подсчет количества уникальных слов
- std::set<std::string> uniqueWords;
- word.clear();
- for (size_t i = 0; i < input.size(); ++i) {
- if (isalnum(input[i]) || input[i] == '-') {
- word += input[i];
- }
- else if (!word.empty()) {
- uniqueWords.insert(word);
- word.clear();
- }
- }
- if (!word.empty()) {
- uniqueWords.insert(word);
- }
- std::cout << "Количество уникальных слов: " << uniqueWords.size() << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement