0
I have the following problem to check the repeating vectors in a Vector:
Given a sequence of n real numbers, determine the numbers that make up the sequence and the number of times each of them occurs in it.
Example:
n = 8
Sequel:
-1.7, 3.0, 0.0, 1.5, 0.0, -1.7, 2.3, -1,7
Exit:
-1.7 occurs 3 times
3.0 occurs 1 time
0.0 occurs 2 times
1.5 occurs 1 time
2.3 occurs 1 time
Here’s the code I wrote so far in C++:
#include <iostream>
using namespace std;
int main () {
int n, i, i2, i3, a, cont=0;
cin>>n;
float vet[n], vet2[n], vet3[n];
for(i=0 ; i<n ; i++){
cin>>vet[i];
vet2[i]=vet[i];
}
for(i=0 ; i<n ; i++){
cont=0;
for(i2=0 ; i2<n ; i2++){
if(vet[i]==vet2[i2]){
cont++;
vet3[i]=vet[i];
}
}
cout.precision(1);
cout<<fixed<<vet[i]<<" ocorre "<<cont<<" vezes"<<endl;
}
return 0;
}
So far I’m having the following result:
the problem is that the repeated values are being shown in the amount of times they contain within the vector, and not just one as asks for the exercise.
:/