Home > Back-end >  The 11th blue bowl individual campus selection problem 4
The 11th blue bowl individual campus selection problem 4

Time:02-10

Topics are as follows:
In 1 to 2019, the number of how many digital contained in the number 9?
Note that the digital include multiple of some number 9, this number is only once, for example, the number of number 9, 1999 in computing is just a number,

Here is a kind of solution
 # include 
Int main ()
{
Int I, a=0;
For (I=1; I<=2019; I++)
{if (I % 10==9 | | I/10% 10==9 | | I/100% 10==9)
+;
}

Printf (" % d ", a);


}

Please bosses see if feasible, or is there a better way,

CodePudding user response:

From the application point of view, the lz solution is possible, because the cycle of 1 to 2019 times soon
If you want to pick, that is, can be directly used to calculate, such as how many kinds of bits is 9, 10 is 9, how many one hundred is how many kinds of, add up to remove can be repeated,


CodePudding user response:

I think this is the most simple way of thinking, complicated things to computer

CodePudding user response:

Replaster again, for your reference:
 # include 
Int main (int arg c, char * argv [])
{
Int I=2019, n=0, m;
While (m=I, I, & gt;=9) {
While (m & gt;=9) {
If (10 m %==9) {n++; break; }
M/=10;
}
}
Printf (" n=% d ", n);
return 0;
}

CodePudding user response:

Contains at least one in every 10 the number 9, for less than one hundred, need to consider the ten digits is 9, is nine to one thousand, calculate how much in total, so that greatly reduce cycle times,
  • Related