AcWing 13-B-blank2. 13- B-填空第二题 顺子日期--关于利用find()查找字符串

原题链接
find()函数的使用
基本使用
C-中的find函数用法_c-find-CSDN博客.png
详细情况点击
https://blog.csdn.net/qq_51271013/article/details/116170964

#include<iostream>
#include<string>
using namespace std;

bool cheak(int year,int month,int day)
{
    string str=to_string(year); 把数字2022转化为字符串形式加入该字符串
    if(month<10) str+='0';
    str+=to_string(month);
    if(day<10) str+='0';
    str+=to_string(day);

    return (str.find("012") != -1)||(str.find("123") != -1); //判断是否含有顺子日期
}

int main()
{
    int year=2022;
    int i,j;
    int ans=0;
    int months[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    遍历月份及日期
    for(i=1;i<=12;i++)
    {
        for(j=1;j<=months[i];j++)
        {
            if(cheak(year,i,j)==true)
            {
                ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}
posted @ 2024-04-16 16:36  MsEEi  阅读(2)  评论(0)    收藏  举报