Тут всё задания
#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;
int main() {
string input;
getline(cin, input);
unordered_map<string, int> words;
string word = "";
for (int i = 0; i < input.size(); i++) {
if (input[i] != ' ') {
word += input[i];
} else {
words[word]++;
word = "";
}
cout << "Number of different words: " << words.size() << endl;
cout << "Number of characters used: " << input.size() << endl;
string newInput = "";
for (auto const &w : words) {
bool isUnique = true;
for (int i = 0; i < w.first.size(); i++) {
for (int j = i + 1; j < w.first.size(); j++) {
if (w.first[i] == w.first[j]) {
isUnique = false;
if (isUnique) {
newInput += w.first + " ";
cout << "Modified text: " << newInput << endl;
return 0;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
Тут всё задания
#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;
int main() {
string input;
getline(cin, input);
unordered_map<string, int> words;
string word = "";
for (int i = 0; i < input.size(); i++) {
if (input[i] != ' ') {
word += input[i];
} else {
words[word]++;
word = "";
}
}
words[word]++;
cout << "Number of different words: " << words.size() << endl;
cout << "Number of characters used: " << input.size() << endl;
string newInput = "";
for (auto const &w : words) {
bool isUnique = true;
for (int i = 0; i < w.first.size(); i++) {
for (int j = i + 1; j < w.first.size(); j++) {
if (w.first[i] == w.first[j]) {
isUnique = false;
}
}
}
if (isUnique) {
newInput += w.first + " ";
}
}
cout << "Modified text: " << newInput << endl;
return 0;
}