简单加法(基本型)

code

#include<algorithm>
#include<iostream>
using namespace std;
bool check(int i){
	int a=i,b=i+1,c=i+2;
	while(a||b||c){
		//TODO test carry bit
		if((a%10+b%10+c%10)/10){
			//TODO have carry bit
			return false;
		}
		a/=10,b/=10,c/=10;//try next bit
	}
	return true;
}
int main(){
	ios::sync_with_stdio(false);
	int n,cnt=0;
	cin>>n;
	for(int i=0;i<n;i++){
		if(check(i)){
			cnt++;
		}
	}
	cout<<cnt<<'\n';
	return 0;
}

ref

ref

posted @ 2022-02-04 12:32  ethon-wang  阅读(28)  评论(0编辑  收藏  举报