当前位置:网站首页>[digital statistics DP] counting problem
[digital statistics DP] counting problem
2022-06-28 06:26:00 【Nathan Qian】
subject

338. Counting problem - AcWing Question bank
AcWing 338. Counting problem - AcWing
explain
- count Function to find from (1,num) Numbers (0-9) Number of occurrences
- If interval is required (a,b), Is equivalent to from the prefix and count The result of the difference in
- about num=abcdefg( Consider as follows ) Be careful x=0 Special circumstances of

Code segment
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int get_num(vector<int>num,int l,int r)
{
int n=0;
for(int i=r;i>=l;i--)
n=n*10+num[i];
return n;
}
int power10(int x)
{
int ans=1;
while(x--)
{
ans*=10;
}
return ans;
}
int count(int n,int x)
{
vector<int>num;
while(n)
{
num.push_back(n%10);
n/=10;
}
n =num.size();
int ans=0;
for(int i=n-1-!x;i>=0;i--)
{
if(i<n-1)
{
ans+=get_num(num,i+1,n-1)*power10(i);
if(!x)ans-=power10(i);
}
if(num[i]==x)ans+=get_num(num,0,i-1)+1;
else if(num[i]>x)ans+=power10(i);
}
return ans;
}
int main()
{
int a,b;
while(cin>>a>>b,a)
{
if(a>b)
swap(a,b);
for(int i=0;i<10;i++)
cout<<count(b,i)-count(a-1,i)<<' ';
cout<<endl;
}
return 0;
}边栏推荐
猜你喜欢

death_ satan/hyperf-validate

RN7302三相电量检测(基于STM32单片机)

Freeswitch uses Mod_ Shot module plays mp3

Speech enhancement - spectrum mapping

FPGA - 7 Series FPGA selectio -07- iserdese2 of advanced logic resources

借助nz-pagination中的let-total解析ng-template

Camx架构开UMD、KMD log以及dump图的方式

freeswitch使用mod_shout模块播放mp3

Batch import of pictures into WPS table by date

【Paper Reading-3D Detection】Fully Convolutional One-Stage 3D Object Detection on LiDAR Range Images
随机推荐
【Paper Reading-3D Detection】Fully Convolutional One-Stage 3D Object Detection on LiDAR Range Images
Use the SQL SELECT count distinct query statement to count the total number of unique values of a field in the database
AutoCAD C # Polyline Small Sharp angle Detection
Students who do not understand the code can also send their own token. The current universal dividend model can be divided into BSC and any generation B
图片按日期批量导入WPS表格
Apple MDM bypass jailfree bypass MDM configuration lock free
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance
Linked list (III) - reverse linked list
AutoCAD C# 多段线自相交检测
Speech enhancement - spectrum mapping
idea根据数据库表生成实体类
Configure redis from 0
Online facing such an online world, the only limitation is our imagination
idea创建类时自动添加注释
浮动与定位
Parsing ng template with let total in NZ Pagination
Floating and positioning
Uni app wechat applet sharing function
Build your jmeter+jenkins+ant
easyui下拉框选中触发事件