跳到正文

个人记录

P10424 [蓝桥杯 2024 省 B] 好数

#SUSPENDED#约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 1 分钟

版本

  1. v1当前

错误原因

由于在字符串前面添加字符是 o(n)o(n) 的,所以超时了。

思路

按照题目意思模拟即可。

代码

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n;
bool check(int x){
	int j=1;
	while(x){
		int v=x%10;
		if((v%2)!=(j%2))return false;
		j++;
		x/=10;
	}
	return true;
}
int ans;
signed main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		if(check(i)){
			ans++;
		}
	}
	cout<<ans;
	return 0;
}
原文