1 条题解

  • 0
    @ 2023-3-13 11:51:14

    C :

    #include<stdio.h>
    int main()
    {
    	int i,n,c=0;
    	scanf("%d",&n);
    	for(i=1900;i<=n;i++)
    	{
    		if((i%4==0&&i%100!=0)||(i%400==0)) c++;
    	}
    	printf("%d",c);
    	return 0;
    }
    

    C++ :

    #include <iostream>
    using namespace std;
    
    int main(){
    	int i,n,c = 0;
    	cin>>n;
    	for(i = 1900;i <= n;i++){
    		if(i%4==0&&i%100!=0 || i % 400==0){
    //			cout<<i<<endl;
    			c++;
    		}
    	}
    	cout<<c;
    }
    

    Pascal :

    var i,s,a:longint;
    begin
    read(a);
    for i:=1900 to a do
    if ((i mod 4=0)and(i mod 100<>0))or(i mod 400=0) then inc(s);
    write(s);
    end.
    

    Java :

    import java.util.Scanner;
    
    public class Main{
    
    public static void main(String[] agrs){
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int s = 0;
    for(int i = 1900;i <= n;i++){
    		
    		if((i % 4 == 0 && i % 100 != 0) || (i % 400 == 0)){
    		s++;
    		}
    }System.out.println(s);
    }
    }
    

    Python :

    n = int(input())
    x = 0
    for i in range(1900, n + 1):
        if((i % 4 == 0) and (i % 100 != 0)) or (i % 400 == 0):
            x += 1
    print(x)
    
    • 1

    信息

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