There was a storm recently on Jolibi village. The storm was so strong that some trees fell. There are some logs of varied length lying on the ground. The village ground can be represented by a string of length N, where the i-th character is either 1 or 0. A single log is represented by consecutive characters of 1, and two different logs are separated by one or more 0. For example, for the string 1100010111, there are 3 logs. The first one at position 1 to 2 with length 2, the second one at position 6 with length 1, and the third one at position 8 to 10 with length 3. As a carpenter, you want to take one of these logs home. Because you are the senior carpenter, you may take the longest log home. Determine the length of the longest log! Format Input The first line contains an integer N, the length of the string. The next line contains a string of length N, which represents the village ground. Format Output Output an integer X, the length of the longest log. Constraints • 1 ≤ N ≤ 104 • the i-th character is either 0 or 1. • At least one log is present on the given string. Sample Input 1  10 1100010111 Sample Output 1  3   Sample Input 2  10 0110011000 Sample Output 2  2 I have code the question Sir, but the code still not run. Help me to fix this code, Sir, thx. Only use #include and C language Sir. #include int main(){ int size; char log[100]; int longest_log = 0; int logs_count=0; scanf("%d", &size); scanf("%s", &log); while(size>0){ if(log== "1"){ logs_count++; } else{ if(longest_log < logs_count){ longest_log = logs_count; } logs_count = 0; } size--; } printf("%d",longest_log); return 0; }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Log


There was a storm recently on Jolibi village. The storm was so strong that some trees
fell. There are some logs of varied length lying on the ground. The village ground can
be represented by a string of length N, where the i-th character is either 1 or 0. A single
log is represented by consecutive characters of 1, and two different logs are separated by
one or more 0. For example, for the string 1100010111, there are 3 logs. The first one at
position 1 to 2 with length 2, the second one at position 6 with length 1, and the third
one at position 8 to 10 with length 3.
As a carpenter, you want to take one of these logs home. Because you are the senior
carpenter, you may take the longest log home. Determine the length of the longest log!


Format Input
The first line contains an integer N, the length of the string. The next line contains a string of length N, which represents the
village ground.


Format Output
Output an integer X, the length of the longest log.


Constraints
• 1 ≤ N ≤ 104
• the i-th character is either 0 or 1.
• At least one log is present on the given string.


Sample Input 1 
10
1100010111


Sample Output 1 
3

 

Sample Input 2 
10
0110011000


Sample Output 2 
2

I have code the question Sir, but the code still not run. Help me to fix this code, Sir, thx.

Only use #include<stdio.h> and C language Sir.

#include <stdio.h>
int main(){
int size;
char log[100];
int longest_log = 0;
int logs_count=0;
scanf("%d", &size);
scanf("%s", &log);
while(size>0){
if(log== "1"){
logs_count++;
}
else{
if(longest_log < logs_count){
longest_log = logs_count;
}
logs_count = 0;
}
size--;
}
printf("%d",longest_log);
return 0;
}

Expert Solution
steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Concept of Threads
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education