Last active
February 5, 2016 21:04
-
-
Save rogerioagjr/a333fa9b56700bad9c29 to your computer and use it in GitHub Desktop.
Código
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Código - F2PJ - OBI 2015 | |
// Rogério Júnior | |
// Complexidade: O(n) | |
#include <cstdio> // scanf e printf | |
#define MAXN 10100 // defino MAXN com 10100 | |
// declaro as variáveis que vou usar | |
int n, seq[MAXN], resp; | |
int main(){ | |
// leio o valor de n | |
scanf("%d", &n); | |
// leio os valores da sequência | |
for(int i=1; i<=n; i++) scanf("%d", &seq[i]); | |
// para cada posição da sequência entre 1 e n-2 | |
for(int i=1; i<=n-2; i++) | |
// vejo se este é o começo de um padrão "100" | |
if(seq[i]==1 && seq[i+1]==0 && seq[i+2]==0) resp++; | |
// no fim, imprimo o valor de resp | |
printf("%d\n", resp); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment