Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int FindKToN(int n, int k){
- int oNum = n;
- int power = 1;
- int i = 0;
- int counter = 0;
- while (n > 0){
- int d = n % 10;
- n /= 10;
- counter += d * (power * i) / 10;
- if(d > k){
- counter += power;
- }else if(d == k){
- counter += oNum % power + 1;
- }
- power *= 10;
- i++;
- }
- return counter;
- }
- int findZero(int n){
- int res = 0, i = 1;
- while(1){
- int b = n/i;
- int c = n%i;
- int a = b/10;
- b = b%10;
- if(a==0){
- return res;
- }
- if(b==0){
- res+=(a-1)*i+c+1;
- }else{
- res+=a*i;
- }
- i*=10;
- }
- }
- int main(){
- int tc,range;
- scanf("%d",&tc);
- for(int i=1;i<=tc;i++){
- int num;
- scanf("%d",&num);
- printf("Case #%d: ",i);
- printf("%d %d %d %d %d %d %d %d %d %d\n",findZero(num),FindKToN(num,1),FindKToN(num,2),FindKToN(num,3),FindKToN(num,4),FindKToN(num,5),FindKToN(num,6),FindKToN(num,7),FindKToN(num,8),FindKToN(num,9));
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement