1 条题解

  • 0
    @ 2023-6-11 12:16:47

    C :

    #include<stdio.h>
    
    void main(){
    	int n,i,g,s,b,c;
    	scanf("%d",&n);
    	
    	c=0;
    	for(i=1;i<=n;i++){
    		g=i%10;
    		s=i/10%10;
    		b=i/100;
    		if(i%7!=0&&(g!=7&&s!=7&&b!=7)){
    			c=c+i;
    		}
    	} 
    		printf("%d",c);
    }
    

    C++ :

    #include <iostream>
    using namespace std;
    
    int main(){
    	int i,n,g,s,b,x = 0;
    	cin>>n;
    	for(i = 1;i <= n;i++){
    		b = i / 100;
    		s = i / 10 % 10;
    		g = i % 10;
    		
    		if(i % 7 != 0 && (b != 7 && s != 7 && g != 7)){
    			x = x + i;
    		}
    	}
    	cout<<x<<endl;
    }
    
    

    Python :

    n=int(input())
    i=1
    s=0
    for i in range(1,n+1):
        a=i//100
        b=i//10%10
        c=i%10
        if i%7==0 or a==7 or b==7 or c==7:
            continue
        if i%7!=0 and a!=7 and b!=7 and c!=7:
            s+=i
            i+=1
    print(s)
    
    • 1

    信息

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