티스토리 뷰

algorithm

[c++] 3의 개수구하기(large)

tonirr 2020. 12. 11. 05:08
  • 3의 개수구하기
#include<stdio.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main() {
	//freopen("input.txt", "rt", stdin);
	int n, cur, k=1, lt=1, rt, res=0;
	scanf("%d", &n);
	while(lt!=0){
		lt=n/(k*10);
		rt=n%k;
		cur=(n/k)%10;
		
		if(cur>3) res=res+((lt+1)*k);
		else if(cur==3) res=res+((lt*k)+(rt+1));
		else res=res+(lt*k);
		
		k=k*10;
	}
	printf("%d\n", res);
	return 0;
}
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함