Luo Gu P1179 digital statistics

Title Description

The Statistical a given range [L, R] of all integers, the number 2 the number of occurrences.

For example a given range [2,22] , number the number 2 appears in the 1 times, the number 12 appears in a time, the number 20 appears in 1, the number 21 appears in a time, the number 22 appears in 2 times, so digital 2 appeared in a total in the range of 6 times.

Input Format

2 positive integers L and R & lt , separated by a space between.

Output Format

Digital 2 number of occurrences.

Sample input and output

Input # 1
2 22
Output # 1
6
Input # 2
2 100
Output # 2
20

Description / Tips

1≤L≤R≤100000

 

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     long long a,b,ans=0,n;
 6     cin>>a>>b;
 7     for(int i=a;i<=b;i++)
 8     {
 9         n=i;
10         while(n!=0)
11         {
12             if(n%10==2){
13                 ans++;
14              }
 15              n = n / 10 ;
16          }
 17      }
 18      cout << years;
19      return  0 ;
20 }

 

 

 

Guess you like

Origin www.cnblogs.com/anbujingying/p/11294881.html