文章

16

粉丝

0

获赞

59

访问

3.0k

头像
数字统计 题解:
P1002 兰州大学机试题
发布于2025年3月15日 21:09
阅读数 165

#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int countDigitTwo(int num){
    int count = 0;
    while(num > 0){
        if(num % 10 == 2){//查看个位数是否为2 
            count++;
        }
        num /= 10;//降一位 
    }
    return count;
}


int main(){
    int L,R;
    scanf("%d %d",&L,&R);
    
    int totalCount = 0;
    for(int i = L;i <= R;i++){
        totalCount += countDigitTwo(i);
    }
    
    printf("%d\n",totalCount);
    
    return 0;
}

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发