• 题解
  • 蓝桥杯C/C++2015B组省赛——星系炸弹(结果填空)

  • @ 2024-4-9 23:59:35

AC 代码

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

int main()
{
    for (int year = 2000; year <= 2022; year ++ )
    for (int month = 1; month <= 12; month ++ )
    for (int day = 1; day <= 31; day ++ )
    {
        if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12);
        else if (month == 2)
        {
            if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
            {
                if (day > 29) break;
            }
            else
            {
                if (day > 28) break;
            }
        }
        else
        {
            if (day > 30) break;
        }
    
         // 设置一个标志变量, 遍历到指定日期就更改标志量
        int flag = 0, cnt = 0;
        if (year == 2014 && month == 11 && day == 9)
            flag = 1;
    
        if (flag == 1)
            cnt ++ ;
    
        // 遍历从 11.9 开始, 但是间隔的日期是从下一天开始算的, 所以是 1000 + 1 = 1001
        if (cnt == 1001)
            cout << year << '-' << month << '-' << day << endl;
    }
  
    return 0;
}

1 条评论

  • @ 2024-4-14 16:24:11

    #include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); bool k=false; ll sum=0; for(ll y=2010;y<=2020;y++){ for(ll m=1;m<=12;m++){ ll day=30; if(m1||m3||m5||m7||m8||m10||m12) day=31; else if(m2){ if(y%40&&y%100!=0||y%4000) day=29; else day=28; } for(ll d=1;d<=day;d++){ if(k) sum++; if(sum15&&k) {cout<<y; if(m<10)cout<<"0"; cout<<m; if(d<10) cout<<"0"; cout<<d; k=false; } if(y2015&&m1&&d1)k=true; } } } // cout<<k<<endl; }

    • 1