+ 2

is there a way to count repetition without an array?

VERY BASIC COMMANDS

28th Dec 2020, 2:29 PM
athena
athena - avatar
20 Answers
+ 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
28th Dec 2020, 5:30 PM
BroFar
BroFar - avatar
+ 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/
28th Dec 2020, 3:26 PM
Lothar
Lothar - avatar
+ 4
Ipang she stated arrays are not allowed not strings so ...
28th Dec 2020, 5:54 PM
BroFar
BroFar - avatar
+ 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 ...
28th Dec 2020, 6:04 PM
Ipang
+ 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
28th Dec 2020, 6:21 PM
BroFar
BroFar - avatar
+ 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 : )
28th Dec 2020, 5:12 PM
Ipang
+ 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
30th Dec 2020, 9:08 AM
BroFar
BroFar - avatar
+ 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?
28th Dec 2020, 5:07 PM
Ipang
+ 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
28th Dec 2020, 6:05 PM
BroFar
BroFar - avatar
+ 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 🤦🏻‍♀️🤦🏻‍♀️
28th Dec 2020, 6:09 PM
athena
athena - avatar
+ 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
28th Dec 2020, 3:12 PM
athena
athena - avatar
+ 1
Ipang no even arrays are not allowed just for, while, do while, if
28th Dec 2020, 5:08 PM
athena
athena - avatar
+ 1
Ipang actually that's as far as i got 😂😂😂
28th Dec 2020, 5:14 PM
athena
athena - avatar
+ 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.
28th Dec 2020, 5:34 PM
Ipang
+ 1
BroFar actually i am a girl :)) and strings are not allowed either :(
28th Dec 2020, 6:00 PM
athena
athena - avatar
+ 1
Martin Taylor thank you very much💕💕
30th Dec 2020, 9:02 AM
athena
athena - avatar
0
bell thanks but i can't use vector
28th Dec 2020, 4:37 PM
athena
athena - avatar
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 🙄
28th Dec 2020, 5:01 PM
athena
athena - avatar
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
30th Dec 2020, 6:12 AM
sid
sid - avatar
0
sid the most repeated number with times of repetition
30th Dec 2020, 9:03 AM
athena
athena - avatar