Home > Back-end >  For the problem of c code.
For the problem of c code.

Time:09-17

A number, each digit Numbers are not the same as beautiful, such as 5640, a repeat Numbers are not, such as 11100, a given range from 1 to 100000, the input is doing this in a range between a neighborhood, then output in this area between number is beautiful, how many have computing complexity requirements, namely algorithm must be concise, which bosses can make, save me,,

CodePudding user response:

Because the largest number is 100000, don't repeat maximum number is 98765, with a maximum of five elements of the array and a said the total number of variables is ok, don't have to dynamic array, efficiency is also high,
A number % 10 bits, in addition to October to remove bits, constantly put the bits in the array, there have been repeated exits, every bit not repeat number, is beautiful,

CodePudding user response:

Concise words:
 
Int ibn (unsigned int n)
{
For (int r, m=0; N; N/a=10)
If (r=n % 10, (m & gt;> R) & amp; 1? 1: (m |=1 & lt; Return n==0;
}


The return value 1 is beautiful, 0 is not beautiful, the rest of the test range you write yourself

CodePudding user response:

refer to the second floor early play big play nuclear response:
concise words:
 
Int ibn (unsigned int n)
{
For (int r, m=0; N; N/a=10)
If (r=n % 10, (m & gt;> R) & amp; 1? 1: (m |=1 & lt; Return n==0;
}


The return value of 1 is beautiful, 0 is not beautiful, the rest of the test range you write yourself


The old is the code to see will understand ~

CodePudding user response:

This is entertainment code, unless the ACM, OJ questions such as the pursuit of as little as possible amount of code (RANK can forward), shouldn't write in the engineering application, this is also the flexibility of side effects,

CodePudding user response:

This interesting

CodePudding user response:

Feeling is the permutation and combination problem,
Num=8 * 8 * 7 * 6 * * 7 * 5 + 9 * 8 + 6 to 9 * 8 + 8 * 7 + 9 * 9

CodePudding user response:

If should be started by 10

CodePudding user response:

A digit is 10
Double-digit is 81 (the first from the 1-9, 2nd from 1 to 9 in the rest of the number and 0)=9 * 9
Three digits is 648 (first from the 1-9, 2nd from 1 to 9 in the rest of the number and 0, the third from the. )=9 * 9 * 8
Four digits are 4536=9 * 9 * 8 * 7
Five digits are 27216=9 * 9 * 8 * 7 * 6
All add up to 32491

CodePudding user response:

It seems I was wrong
A digit is nine
Add up to 9 + 9 + 9 * 9 * 9 * 9 * 9 * 8 * 8 + 8 * 7 * 7 + 9 * 9 * 6
=32490

CodePudding user response:

Put the number into a string, bit by bit to check, do not have the same character is beautiful,
The concise is not enough? No mathematical operations.



  • Related