【2023春招】武汉微派研发岗笔试AK

T1-统计数字问题

#include <iostream>
#include <string>
#include <assert.h>
#include <math.h>
using namespace std;

void statistic(int n, int bit, int a[]) {
  if(bit>0) {
    int b=bit-1, high, last, c, i;
    high = n / round(pow(10,b));
    last = n % (int)round(pow(10,b-1));
    c = high * b * round(pow(10,b-1));
    for(i=0; i<10; i++) {
      a[i] += c;
    }
    for(i=0; i<high; i++) {
      a[i] += round(pow(10,b));
    }
    a[high] += (last+1);
    statistic(last, b, a);
  }
}

void del_zero(int bit, int a[]) {
  int c_zero = 0;
  for(int i=bit; i>0; i--) 
    c_zero = c_zero + round(pow(10, i-1));
  a[0] -= c_zero;
}

void output(int a[]) {
  int i=0;
  for(i=0; i<10; i++) {
    cout << i << ":" << a[i] << endl;
  }
}

猜你喜欢

转载自blog.csdn.net/Luoxiaobaia/article/details/129628326