Skip to content

Instantly share code, notes, and snippets.

@rogerioagjr
Last active February 5, 2016 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rogerioagjr/a333fa9b56700bad9c29 to your computer and use it in GitHub Desktop.
Save rogerioagjr/a333fa9b56700bad9c29 to your computer and use it in GitHub Desktop.
Código
// 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