1

Есть две переменные типа string.

Нужно сравнить слова, и вывести уникальные.

Я читаю первую строку до пробела, чтобы вырезать слово, и сравнить её со второй строкой. Но как реализовать?

int main() {
    string s1, s2,t;
    stringstream gg;
    ifstream fin("input.txt");
    cout << "Vvedite vhodnuyu stroku"<<endl;
    getline(cin,s2);
    if (fin.is_open())
    {
        while (!fin.eof())
        {
            getline(fin,s1);
            for (int i = 0; s1[i]; i++)
            {
                if(s1[i] != ' ')
                {

                }
            }
        }
    }
    fin.close();
    system("pause");
}

1 ответ 1

1
string s1;    
stringstream gg;
map<string, int> m;
if (fin.is_open() {
    while (getline(fin, s1))
        gg << s1;
    while (gg >> s1)
        ++m[s1];
    for (const auto& p : m) {
        static int k = 0;
        if(++k == 10)
            cout << '\n';
        if(p.second == 1)
            cout << p.first <<' ';
    }
}

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.