第十三届蓝桥杯 C++ B组题解:

第十三届蓝桥杯 C++ B组题解:

A:进位制

(2022)9= 2 * 9^3 + 2 * 9+ 2=1478

B:顺子日期:(0,1,2算顺子,逆序不算)

枚举,14个

#include 
#include 
#include 

using namespace std;

const int months[]={
    0,31,28,31,30,31,
    30,31,31,30,31,30,
    31
};

bool check(string str)
{
    for (int i = 0; i < str.size(); i ++ )
    {
        if(str[i+1]==str[i]+1 && str[i+2]==str[i]+2)
            return true;
    }
    return false;
}

int main()
{
    int year=2022,month=1,day=1;
    int res=0;
    
    for (int i = 0; i < 365; i ++ )
    {
        char str[10];
        sprintf(str,"%04d%02d%02d",year,month,day);//格式化数据写入字符串
        
        if(check(str))
        {
            res++;
            cout << str <

你可能感兴趣的:(C++,c++,蓝桥杯,算法)