Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct node Node;
- struct node {
- char item;
- Node *next;
- };
- Node* insert_begin(Node *aux, char num) {
- Node *new_node = (Node*) malloc(sizeof(Node));
- new_node->item = num;
- new_node->next = NULL;
- if (aux != NULL) aux->next = new_node;
- return new_node;
- }
- void highest_sequence(Node *head) {
- int freq = 0, max = 0;
- int aux_initial, aux_final, start, end;
- int i = 0;
- while (head != NULL) {
- if (head->item == '0') {
- if (freq == 0) aux_initial = i;
- aux_final = i;
- freq++;
- }
- //printf(" frequen %d\n", freq);
- if (head->item == '1' || head->next == NULL) {
- if (freq > max) {
- max = freq;
- start = aux_initial;
- end = aux_final;
- }
- freq = 0;
- }
- i++;
- head = head->next;
- }
- printf("%d %d\n", start, end);
- }
- void print_list(Node *head) {
- while (head != NULL) {
- printf("%c - > ", head->item);
- head = head->next;
- }
- printf("\n");
- }
- int main() {
- Node *head = NULL;
- Node *aux = NULL;
- char string[1000];
- int i;
- while (1) {
- scanf("%s", string);
- getchar(); // pega o \n.
- if (strcmp(string, "0") == 0) break;
- for (i = 0; i < strlen(string); i++) {
- aux = insert_begin(aux, string[i]);
- if (head == NULL) head = aux;
- }
- highest_sequence(head);
- head = NULL;
- //print_list(head);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement