Проблем със задача 4, от второто домашно. ( Most Frequent Number)
Здравейте, някой може ли да ми помогне да си изведа стойностите за maxValue и equalValues, от първия вектор (vector). В момента ми извежда клетката от паметта, в която са копирани.
// 4.BasicSyntaxMostFrequentNumber.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <algorithm>
void mostFrequentNumber(std::vector <int> vector, int vectorSize)
{
int counterZeroes = 0, counterOnes = 0, counterTwos = 0, counterThrees = 0, counterFours = 0, counterFives = 0,
counterSixs = 0, counterSevens = 0, counterEights = 0, counterNines = 0;
int maxValue = 0;
for (int i = 0; i < vectorSize; i++)
{
switch (vector[i])
{
case 0:counterZeroes++;
break;
case 1:counterOnes++;
break;
case 2:counterTwos++;
break;
case 3:counterThrees++;
break;
case 4:counterFours++;
break;
case 5:counterFives++;
break;
case 6:counterSixs++;
break;
case 7:counterSevens++;
break;
case 8:counterEights++;
break;
case 9:counterNines++;
break;
}
}
std::vector<int>counters{ counterZeroes, counterOnes, counterTwos, counterThrees, counterFours, counterFives, counterSixs,
counterSevens, counterEights, counterNines };
counters.erase(std::remove(counters.begin(), counters.end(), 0), counters.end());
std::vector<int>equalValues;
for (int i = 0; i < counters.size(); i++)
{
std::cout << counters[i] << std::endl;
if (i > 0)
{
if (counters[i] > counters[i - 1])
{
maxValue = counters[i];
}
else if (counters[i] == counters[i - 1] && counters[i] == maxValue)
{
equalValues.push_back(counters[i]);
}
}
}
std::cout << &maxValue << std::endl;
for (int i = 0; i < equalValues.size(); i++)
{
std::cout << &equalValues[i] << std::endl;
}
}
int main()
{
int vectorLength;
std::cin >> vectorLength;
std::vector<int>v;
for (int i = 0; i < vectorLength; i++)
{
static int number;
std::cin >> number;
v.push_back(number);
}
mostFrequentNumber(v, vectorLength);
return 0;
}
Благодаря ти. Оправих всичко.