2 条题解

  • 0
    @ 2025-5-19 23:38:55
    #include<iostream>
    
    bool j(int y)
    {
    	return (y % 4 == 0 && y % 100 != 0) || y % 400 == 0;
    }
    
    void solve(int date[3])
    {
    	int they{date[0]}, them{date[1]}, tdby{date[2]};
    	int m[13] = {29,
    		31, 28, 31,
    		30, 31, 30,
    		31, 31, 30,
    		31, 30, 31
    	};
    	if(tdby - 2 <= 0) {
    		if(j(they) && them == 3) {
    			tdby += m[0] - 2;
    			them = 2;
    		}
        else if(them == 1) {
    			they--;
    			them = 12;
    			tdby += m[12] - 2;
    		}
        else {
    			them--;
    			tdby += m[them] - 2;
    		}
    	}
      else {
    		tdby -= 2;
    	}
    	printf("%d-%02d-%02d", they, them, tdby);
    }
    
    int main()
    {
    	int date[3];
    	scanf(
    		"%d-%d-%d",
    		&date[0], &date[1], &date[2]
    	);
    	solve(date);
    	return 0;
    }
    
    

    信息

    ID
    45
    时间
    1000ms
    内存
    256MiB
    难度
    9
    标签
    递交数
    20
    已通过
    2
    上传者