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;
}
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
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP