文章

19

粉丝

0

获赞

66

访问

3.3k

头像
这是第几天? 题解:利用rfind函数
P1542 云南大学/暨南大学机试题
发布于2026年3月23日 21:44
阅读数 81

#include<bits/stdc++.h>
using namespace std;

bool isYear(int x){
    if((x%400==0)|| ((x%4==0) && (x%100!=0)) ){
        return true;
    }else{
        return false;
    }
}

int mouth[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

int main(){
    string s;
    cin >> s;
    int ans = 0; 
    int pos1 = s.find('-');
    int pos2 = s.rfind('-');
    int y = stoi(s.substr(0,pos1));
    int m = stoi(s.substr(pos1 + 1, pos2 - pos1 - 1));
    int d = stoi(s.substr(pos2 + 1));
    if(isYear(y)){
        mouth[2]=29;
    }
    for(int i=1;i<m;i++){
        ans += mouth[i];
    }
 ...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发