🐏🐏🐏
🐏写在前面🐏
刚打完蓝桥杯省赛B组,小🐏还差得远呢,这跟题解中的代码除了第一题,其他的都是看y总直播时候写的
看完本篇文章觉得不错的话记得点赞👍,收藏⭐,还有问题也可以评论留言💬
🐏填空题🐏
🐏试题 A: 九进制转十进制🐏
这道题是填空题,我们只需要算2×90+2×91+2×93,最后等于1478。
#include<iostream>
using namespace std;
int main()
{
cout << 2+2*9+2*9*9*9;
}
🐏试题 B: 顺子日期🐏
这题题意有点问题
所以很给人误解,到底012算还是不算,在这我们不纠结题意,只看怎么解决。
#include <iostream>
#include <cstring>
#include <algorithm>
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 + 2 < 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 << endl;
}
if ( ++ day > months[month])
{
day = 1;
month ++ ;
}
}
cout << res << endl;
return 0;
}
答案:14
如果012不算,那就加一个限制条件
if (check(str)&&str[i] != 0)
#include <iostream>
#include <cstring>
#include <algorithm>
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 + 2 < 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)&&str[i] != 0)
{
res ++ ;
cout << str << endl;
}
if ( ++ day > months[month])
{
day = 1;
month ++ ;
}
}
cout << res << endl;
return 0;
}
最后答案就是:4
🐏编程题🐏
🐏试题 C: 刷题统计🐏
这题需要注意数据范围,我们得开long long
#include <iostream>
#include <cstring>
#include <algorithm>
us