1 条题解

  • 0
    @ 2023-6-11 12:17:10

    C :

    #include<stdio.h>
    
    void main(){
    	int x,m,n,p=0,g,s,b,q,i;
    	scanf("%d\n",&x);
    	scanf("%d",&m);
    	scanf("%d",&n);
    	
    	for(i=m;i<=n;i++){
    		g=i%10;
    		s=i/10%10;
    		b=i/100%10;
    		q=i/1000;
    		if(g==x||s==x||b==x||q==x){
    			p++;
    		} 
    	}
    	printf("%d",p); 
    		
    }
    

    C++ :

    #include <iostream>
    using namespace std;
    
    int main(){
    	int x,g,s,b,q,i,c = 0,m,n;
    	cin>>x;
    	cin>>m>>n;
    	for(i = m;i <= n;i++){
    		g = i % 10;
    		s = i / 10 % 10;
    		b = i / 100 % 10;
    		q = i / 1000;
    		if(g == x || s == x || b == x || q == x){
    			c++;
    		}
    	}
    	cout<<c<<endl;
    	
    }
    
    
    

    Python :

    x = int(input())
    y = input().split()
    m = int(y[0])
    n = int(y[1])
    c = 0
    for i in range(m, n + 1):
        q = i // 1000 % 10
        b = i // 100 % 10
        s = i // 10 % 10
        g = i // 1 % 10
        if q == x or b == x or s == x or g == x:
            c += 1
    print(c)
    
    • 1

    信息

    ID
    2365
    时间
    1000ms
    内存
    32MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者