+ 2
is there a way to count repetition without an array?
VERY BASIC COMMANDS
22 Réponses
+ 11
Ipang I was looking at this as well but
int size = 100;
cin.getline(num, size);
or
cin.getline(num[100]);
but doubt that either would work right
+ 8
athena , i am not very experienced in C++, but why not using something like a dictionary? In python we use this as a counter.
https://www.techiedelight.com/increment-map-value-associated-with-key-cpp/
+ 4
Ipang she stated arrays are not allowed not strings so ...
+ 4
Without all the restrictions applied, many others had recommended good & viable options BroFar sir.
There are times when assignments got funny requirements, I guess this is just one of them ...
+ 4
Sounds more like a do while
int i = 0;
int a;
do {
cin >> a;
cout << a << endl;
i++;
}
while (i < 101);
https://code.sololearn.com/c3yORki033ec/?ref=app
+ 3
So the values aren't getting saved anywhere, and they're just read in?
That's tricky though.
In that case maybe, to have 21 variables each representing a number's frequency.
Dumb idea, I know : )
+ 3
athena I made a code that also might demonstrate but at the end I did create an array from the results of the initial result to find the exact numbers
https://code.sololearn.com/cYclByYbE2NS/?ref=app
+ 2
But you are allowed to use array to store the values right athena?
Just you're not allowed to use array as frequency counter?
+ 2
athena whoa so you have to cin each number then use an exit like 00 so
int num;
int ct;
if (num == 00) { break;} else { ct++;} or something like that
if I understand your question correctly
+ 2
BroFar kinda thinking about other ways is kinda stupid i guess i shoud declare 21 variable each representing a number between 0-20 then write a for loop for 100 times and each time it should compare it with the other 21 variables sooooo stupid 🤦🏻♀️🤦🏻♀️
+ 1
Martin Taylor actually i have to get 100 numbers between 0-20 and i should recognize the most repeated number and count it
the print it as the output
+ 1
Ipang no even arrays are not allowed just for, while, do while, if
+ 1
Ipang actually that's as far as i got 😂😂😂
+ 1
Might work if string was allowed BroFar sir ...
But then, if string was allowed, Bell's recommendation to use char (e.g. in a string) to count frequency would have solved this task straight on.
+ 1
BroFar actually i am a girl :))
and strings are not allowed either :(
+ 1
Martin Taylor thank you very much💕💕
0
bell thanks but i can't use vector
0
bell it's my homework and our teacher wants us to use loops and conditionals only
and btw i didn't get your code 🙄
0
Do you have to print only the largest repeated number or print the repetition times of each number. ?
If it is the former then there exists a way
0
sid the most repeated number with times of repetition