Ввести 2 предложения, а затем исключить слова во втором предложении, которые имеются в первом. После чего вывести полученное второе предложение.
Смог сделать только удаление первого предложения. Подскажите пожалуйста.
#include <string>
#include <iostream>
using namespace std;
int main() {
string non;
getline(cin, non);
int i;
int b = 0;
for (i = 0; i <= non.length(); i++) {
if (non.at(i) == '.') {
break;
}
b++;
}
b = b + 2;
cout << b << endl;
non.erase(0, b);
cout << non;
return 0;
}
#include <vector>
#include <string>
#include <algorithm>
#include <sstream>
#include <iostream>
// Ввести 2 предложения, а затем исключить слова во втором предложении,
// которые имеются в первом. После чего вывести полученное второе предложение.
using str_vector_t = std::vector<std::string>;
template<template<typename...> typename Container, typename T>
bool contains(const Container<T>& c, const T& value) {
return c.cend() != std::find_if(c.cbegin(), c.cend(), [&](const T& ref_value) {
return ref_value == value;
});
}
void split_string(const std::string& sentence, str_vector_t& words);
int main() {
const auto sentence_f = "Show me you are a big boy";
const auto sentence_s = "Let me stop you there big boy"; // me you big boy
str_vector_t words_f, words_s;
split_string(sentence_f, words_f);
split_string(sentence_s, words_s);
words_s.erase(
std::remove_if(words_s.begin(), words_s.end(), [&](const auto& word_s) {
return contains(words_f, word_s);
}), words_s.end());
std::cout << "Result: ";
for (const auto& word : words_s)
std::cout << word << ' ';
return 0;
}
void split_string(const std::string& sentence, str_vector_t& words) {
std::string word;
std::stringstream stream { sentence };
while (std::getline(stream, word, ' '))
words.emplace_back(std::move(word));
};
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
string first;
string second;
string newStr = "";
string buf = "";
getline(cin, first);
int i = first.find(".");
second = first.substr(0, i);
for (i++; i < first.length(); i++) {
if (first[i] != ' ') {
buf += first[i];
}
if (first[i] == ' ' || i == first.length() - 1) {
if (second.find(buf) == std::string::npos && buf != " ") {
newStr += buf + ' ';
buf = "";
}
else { buf = ""; }
}
}
cout << newStr;
system("pause");
return 0;
}
Думаю можно лучше придумать, но пока как есть ) Если нужны будут комментарии, отпишите
Оборудование для ресторана: новинки профессиональной кухонной техники
Частный дом престарелых в Киеве: комфорт, забота и профессиональный уход
Никак не могу найти информацию, которая бы детально описывала правила продвижения малых целых типов в C++