Ошибки:Максимальное количество дублей
Описание Путь информационного ресурса Тип не может преобразовать '__gnu_cxx :: __ alloc_traits>> :: value_type {ака станд :: basic_string}' на 'Int' в уступке duplicatedWords.cpp/duplicatedWords/src строка 42 C/C++ Проблема не может преобразовать '__gnu_cxx :: __ alloc_traits>> :: value_type {aka std :: basic_string}' в 'int' в инициализации duplicatedWords.cpp/duplicatedWords/src line 37 C/C++ Задача не может convert 'std :: basic_string' в 'int' в инициализации duplicatedWords.cpp/duplicatedWords/src line 40 C/C++ Задача Нет совпадения для 'operator>' (типы операндов: '__gnu_cxx :: __ alloc_traits>> :: value_type {aka std :: basic_string} 'и' INT ') duplicatedWords.cpp/duplicatedWords/ЦСИ строка 41 C/C++ Проблема
/*
Write a program to read strings from standard input
looking for duplicated words. The program should find places in the input
where one word is followed immediately by itself. Keep track of the largest
number of times a single repetition occurs and which word is repeated. Print
the maximum number of duplicates, or else print a message saying that no
word was repeated. For example, if the input is
how now now now brown cow cow
the output should indicate that the word now occurred three times.
*/
#include <iostream>
#include <vector>
using namespace std;
int main() {
cout << "Please enter your words " << endl;
string words;
vector<string> vec;
while(cin>>words && words != "qu"){
vec.push_back(words);
}
int max = vec[0];
int result = 0;
for(int i: vec){
if(vec[i] > max){
max = vec[i];
result = i;
}
}
cout<<result<<endl;
return 0;
}
Я теряюсь о том, как я могу найти максимальный дублируют – TheChessDoctor
Во-первых, у вас есть строка вектор и вы делаете некоторые струнные вещи с ним. ОК. Затем, внезапно, остальная часть кода похожа на вектор, содержащий целое число, которое может быть присвоено 'int' и по сравнению с'> '. Что делаешь?! – deviantfan
Что произойдет, если пользователь введет 'qu' в качестве первого входа? Обращайтесь с этим делом изящно. –