当前位置:网站首页>[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;
}边栏推荐
- Error reporting - resolve core JS / modules / es error. cause. JS error
- 异常处理(一)——空指针和数组索引越界
- CAD secondary development +nettopologysuite+pgis reference multi version DLL
- Yolact++ Pytorch环境
- JS of learning notes -- split(), replace(), join()
- FPGA - 7系列 FPGA SelectIO -08- 高级逻辑资源之OSERDESE2
- death_satan/hyperf-validate
- Triode driven brushless motor
- 职场IT老鸟的几点小习惯
- 使用SSM框架,配置多个数据库连接
猜你喜欢

语音增强-频谱映射

链表(二)——设计链表

socke. IO long connection enables push, version control, and real-time active user statistics

AutoCAD C# 多段線小銳角檢測

【网络教程】IPtables官方教程--学习笔记1

FPGA - 7 Series FPGA selectio -08- oserdese2 of advanced logic resources

Uni app wechat applet sharing function

Caused by: com. fasterxml. jackson. databind. exc.InvalidDefinitionException: Cannot construct instance

Common basic functions of Oracle

浮动与定位
随机推荐
Use the SQL SELECT count distinct query statement to count the total number of unique values of a field in the database
MySQL (II) - basic operation
Differences between basic types and packaging classes
socke.io長連接實現推送、版本控制、實時活躍用戶量統計
How the third-party libraries in cocoapod reference local header files
Note that JPA uses a custom VO to receive jpql query results
Configure multiple database connections using the SSM framework
Linux Mysql 实现root用户不用密码登录
Object object to list collection
AutoCAD C polyline self intersection detection
Differences between overloads, rewrites, abstract classes and interfaces
Paper recommendation: efficientnetv2 - get smaller models and faster training speed through NAS, scaling and fused mbconv
death_ satan/hyperf-validate
Shell script one click deployment (MySQL)
ThreadLocal
OpenGL API learning (2008) client server client server
socke. IO long connection enables push, version control, and real-time active user statistics
idea创建类时自动添加注释
Taobao seo training video course [22 lectures]
整型提昇和大小端字節序