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;
}