AnswerBun.com

Подскажите, как можно заменить эту ошибку, что бы не переделывать код? Отсутствует оператор "[]", соответствующий этим операндам

Stack Overflow на русском Asked by John Maksimenko on November 12, 2020

#include <iostream>
#include <list>
#include <iterator>
#include <map>

using namespace std;

int main()
{
    string word;
    list<string> list;
    map<string, int> reiteration;
    map<int, int> max_min;
    while (word != "/") {
        cin >> word;
        if (word != "/")list.push_back(word);
    }
    for (unsigned int i = 0; i < list.size(); i++) {
        word = list[i];
        reiteration.insert(pair<string, int>(word, 1));
        max_min.insert(pair<int, int>(i, 1));
        auto rep = max_min.begin();
        for (auto it = reiteration.begin(); it != reiteration.end(); it++, rep++) {
            if (it->first == word) {
                it->second++;
                rep->second = i;
            }
            else {
                reiteration.insert(pair<string, int>(word, 1));
            }
        }
    }
    auto rep = max_min.begin();
    for (auto it = reiteration.begin(); it != reiteration.end(); it++) {
        cout << "Word`s : " << it->first << " repeated : " << it->second - 1 << " times" << endl;
        if (it->second - 1 > 1) {
            cout << "position 1 : " << rep->first + 1 << " position 2 : " << rep->second + 1 << endl;
            rep++;
        }
    }
    return 0;
}

2 Answers

list<string> list;

Не нужен он тебе, используй vector:

vector<string> list;

Answered by Qwertiy on November 12, 2020

for (unsigned int i = 0; i < list.size(); i++) {
    word = list[i];
unsigned int i = 0; 
for (string word : list) {
  ...
  ++i;
}

Answered by Qwertiy on November 12, 2020

Add your own answers!

Related Questions

Конвертация строки в дату python

2  Asked on December 2, 2021 by ss_beer

   

Как и где лучше хранить API ключ

2  Asked on December 2, 2021 by russian-stan

   

webpack.config.js синтаксис

1  Asked on December 2, 2021 by jarry-roxwell

     

Что за тип данных PUCHAR

1  Asked on December 2, 2021 by krime

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir