当前位置:网站首页>1016. substring can represent binary string of numbers from 1 to n
1016. substring can represent binary string of numbers from 1 to n
2022-06-21 23:13:00 【Mr Gao】
1016. A substring can represent from 1 To N A binary string of numbers
Given a binary string s And a positive integer n, If for [1, n] Every integer in the range , Its binary representation is s Of Substring , Just go back to true, Otherwise return to false .
Substring Is a sequence of consecutive characters in a string .
Example 1:
Input :s = “0110”, n = 3
Output :true
Example 2:
Input :s = “0110”, n = 4
Output :false
int len;
char *f(int n){
len=0;
int p=n;
while(p){
len++;
p=p/2;
}
char *cs=(char *)malloc(sizeof(char)*(len+1));
int i=0;
p=n;
while(p){
// printf(" %d ",len-i-1);
cs[len-i-1]='0'+p%2;
i++;
p=p/2;
}
cs[len]='\0';
// printf("%s ",cs);
return cs;
}
bool f2(char *s, char *cs,int len){
int i;
for(i=0;i<len;i++){
if(s[i]!=cs[i]){
return false;
}
}
return true;
}
bool queryString(char * s, int n){
int i;
int j;
for(j=1;j<=n;j++){
int r=0;
char *cs=f(j);
int sl=strlen(s);
for(i=0;i<=sl-len;i++){
if(f2(cs,s+i,len)){
r=1;
break;
}
}
if(r!=1){
return false;
}
}
return true;;
}
边栏推荐
- WPF tablet
- Solve the problem that the letter of a key in laptop (I) cannot be pressed
- uniapp封装request函数 实现唯一登录,一个账号同时只能登陆一个设备
- Design and implementation of spark offline development framework
- 小程序如何关联微信小程序二维码,并实现二码合一聚合
- [wustctf2020] plain and unpretentious -1
- mvn deploy多个模块的bat文件
- 4. esp8266 displays DHT11 temperature and humidity parameters in real time through OLED
- 有一说一,高并发系统设计其实一点都不难!
- 解决opencv在pycharm中代码提示失效
猜你喜欢

What is the most challenging issue in Bi development?
Swiftui basic learning journal (XI) SQLite data operation
![[wustctf2020] plain and unpretentious -1](/img/e8/96835a7b4f1e892b0c78ccf7bda2c2.png)
[wustctf2020] plain and unpretentious -1

解决opencv在pycharm中代码提示失效

STM32 cannot download the program again after downloading it once, and the program cannot run.

WPF 线程操纵UI问题

Some users of uniapp wechat authorization cannot be authorized normally

Software testing Q & A

并查集练习题1:朋友圈

Uniapp version update hot update and natural update
随机推荐
上海交通大学:Kerong Wang | 基于离线强化学习的自举Transformer
The way of FPGA -- project scheme and FPGA design scheme of FPGA development process
并查集练习题1:朋友圈
Software testing Q & A
WPF combobox setting options and anti display
4. ESP8266通过OLED实时显示DHT11温湿度参数
Apache shardingsphere 5.1.2 release | new driving API + cloud native deployment to create a high-performance data gateway
[understanding pointer] advanced level of pointer
[wustctf2020] plain and unpretentious -1
Better manage all kinds of music, professional DJ music management software pioneer DJ rekordbox
How to adjust the resolution of the computer screen? Computer screen modification resolution switchresx
STM32F407程序移植到STM32F429
mysql中数据格式转换的一个示例
Translation software Bob installation tutorial
About LG (n!) Asymptotically compact supremum of
Postgres slice data through limit
《MATLAB 神经网络43个案例分析》:第19章 基于SVM的手写字体识别
Guys, some field updates of starrocks PK model in 2.2.1 still do not support SQL, right?
【用四道刁钻例题带你理解】数据在内存中存储的方式
Functions for automatically calculating bit width during Verilog parameterization