Friday, December 14, 2018

[UVa] 12241 - Digits Count

Author            : Dipu Kumar Mohanto 
                    CSE, Batch - 6
                    BRUR.
Problem Statement : 12241 - Digits Count
Source            : Light Online Judge
Category          : Dynamic Programing
Algorithm         : Digit DP
Verdict           : Accepted
Type - 3
#include "bits/stdc++.h"
 
using namespace std;
 
#define ll            long long
 
inline void digitCount(int digit[], int n)
{
      int temp = n;
      int base = 1;
      while (temp)
      {
            if (n >= base) digit[0] -= base;
            digit[temp % 10] += n % base + 1;
            int t = temp % 10;
            for (int i = 0; i < t; i++) digit[i] += base;
            temp /= 10;
            for (int i = 0; i < 10; i++) digit[i] += temp * base;
            base *= 10;
      }
}
 
int arr1[10], arr2[10];
 
int main()
{
      int a, b;
      while (cin >> a >> b, a, b)
      {
            if (a > b) swap(a, b);
            for (int i = 0; i < 10; i++) arr1[i] = arr2[i] = 0;
            digitCount(arr1, a-1);
            digitCount(arr2, b);
            cout << arr2[0] - arr1[0];
            for (int i = 1; i < 10; i++) cout << " " << arr2[i] - arr1[i];
            cout << endl;
      }
}
 
 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.