当前位置:网站首页>1157: n consecutive ones
1157: n consecutive ones
2022-04-21 09:10:00 【Qian Qian】
1157: Successive n individual 1
Title Description
Computer data is made up of 0 and 1 Composed of , Look at the long 0101001110101111011, To find continuity n individual 1 How many substrings are there , It's a real hassle , Please program it .
Input
Enter a string for the first line , from 0 and 1 form , The length is less than 1000; Enter a positive integer for the second line n.
Output
Output an integer , Means continuous n One of the 1 The number of substrings of .
The sample input Copy
0101001110101111011
2
Sample output Copy
6
source / classification
#include<stdio.h>
#include<string.h>
#define MAX 1000
int main(){
char s[MAX];
int n,f=0,count=0;
scanf("%s%d",&s,&n);
// Pay attention to the interval [0-strlen(s)-n]
for(int i=0;i<=strlen(s)-n;i++){
if(s[i]=='1'){
f=1;
// Satisfy (i-i+n) common n individual 1,f=1
for(int j=i;j<i+n;j++){
if(s[j]=='0') {
f=0;
break;
}
}
if(f==1) count++;
}
}
printf("%d\n",count);
return 0;
}
版权声明
本文为[Qian Qian]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210906131992.html
边栏推荐
- [(strongly pushed) Li Hongyi 2021 / 2022 spring machine learning course] unsupervised learning - linear methods
- Simulated 100 questions and simulated examination of Shanghai safety officer C certificate examination in 2022
- 1152: 二分搜索
- Grid division [DFS]
- 数据库有张表,其中一个字段存的是json数据,我需要在这张表有更新的时候,解析这个字符串,然后把解析的json数据更新到另外一个表,有什么好的建议?
- [GYCTF2020]Blacklist
- A value is trying to be set on a copy of a slice from a DataFrame.
- 1155: 字符串比较 多实例
- 1153: 简易版最长序列
- 2022 tea artist (primary) examination questions and online simulation examination
猜你喜欢

Based on ASP Net online flower shopping management

目标检测入门常见问题(深度学习 / 图像分类)

2022 chemical automation control instrument examination exercises and simulation examination

Handler asynchronous message passing mechanism (I) common basic usage of handler

Netease blog is going to be closed. My article!
![BUUCTF[HCTF 2018]WarmUp](/img/89/5d7d147dfb8e2bc10a2ff0bb68debe.png)
BUUCTF[HCTF 2018]WarmUp

Characteristics of interactive multimedia applications

Meizu, once expected to challenge apple, now lives by providing accessories for Apple users

Handler异步消息传递机制(一)Handler常用基本用法

Detailed explanation of native and H5 mixed development
随机推荐
Characteristics of interactive multimedia applications
2022 t elevator repair test questions and online simulation test
批量处理数据对比(<foreach>标签和sqlsession)
1163: 亲和串(字符串)
1153: 简易版最长序列
1152: binary search
2022 tea artist (primary) examination questions and online simulation examination
CC00019.CloudJenkins—————————————
Notes of the most complete grain mall in the whole network_ 02. Introduction to the overall effect of the project (2022-04-02)
网易博客居然要关了,我写的文章啊!
Surfaceview high performance rendering (IV) code practice - drawing multiple pictures
Simulation implementation vector
1151: 大整数加法
Is annuity insurance safe and reliable? How much is the profit?
[CTF. Show. Reverse] moon cake cup RE1_ Northwest Wangxiang, re2_ Homing, RE3_ If there is no month
Geek challenge 2019 upload 1
编程如何提高自己的水平能力?学编程最重要的是什么?请看凡人浅谈如何学C
Convolution operation and cross correlation operation
规划自己的健康问题
我的博客导航目录(持续整理更新中。。。)