Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main(void) {
- int arr[] = { 10,100,5,-4,-89,29,-2,-8,-49,-499,0,94 };
- int n = sizeof(arr) / sizeof(arr[0]);
- int seq_start = -1;
- int longest_seq = 0;
- for ( int i=0; i<n; ++i ) {
- if ( arr[i] < 0 ) {
- if ( seq_start < 0 ) {
- seq_start = i;
- }
- } else if ( seq_start > -1 ) {
- printf("seq found (%d,%d) (len=%d)\n", seq_start, i-1, i-seq_start);
- if ( i-seq_start > longest_seq ) {
- longest_seq = i-seq_start;
- }
- seq_start = -1;
- }
- }
- printf("longest: %d\n", longest_seq);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment