A number 'i' is a magic number if for each digit 'j' in the number, there are exactly j occurences of it. For example, 1 is a magic number since there is 1 occurence of digit 1.Similarly 212 is also a magic number since there is 1 occurence of digit 1 and 2 occurences of digit 2. On the other hand, 12 and 123 are not magic numbers since 2 and 3 only occur once.
Given a positive integer P, your task is to decide whether P is a magic number.
Input
The first line consists of an integer N (1 <= N <= 10), the number of test cases. The next N lines contains a positive integer P consisting of M digits (1 <= M <= 100).
Output
For each test case, output YES if the input is a magic number. Otherwise, output NO.
Can anyone see whats wrong with the function magicnumber or the main function because both of the above inputs are magic numbers and i expected the output to be like 20 lines of matches for the first one and YES and for the second one 14 lines of matches and YES?
If int is 32 bits wide, the maximum number it can hold is 2^31-1 = 2,147,483,647.
You should read the number as a string if you want to allow inputs of arbitrary length.
its not that, array is of a fixed since the input will definitely not exceed 100 digits as mentioned in the question. its something else. plus the inputs that dont work are 20 digits and 14 digits respectively. must be a the algorithm
its not that, array is of a fixed since the input will definitely not exceed 100 digits as mentioned in the question. its something else. plus the inputs that dont work are 20 digits and 14 digits respectively. must be a the algorithm
As @Athar said you are ttrying to enter an acceptable value for a variable of type int. So the input stream ( I do not check) either truncates your input or issues an error.
You can output entered value that to be sure what value is being processed.