Created
June 8, 2016 14:45
-
-
Save rogerioagjr/3cb20e7a136c7410ebadfda7cc4dc69c to your computer and use it in GitHub Desktop.
Chaves
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
// Chaves - F1P2 - OBI 2016 | |
// Rogério Júnior | |
// Complexidade: O(entrada) | |
#include <cstdio> | |
int qtd; | |
bool erro; | |
char c; | |
int main(){ | |
// leio todos os caracteres da entrada | |
while(scanf("%c", &c)!=EOF){ | |
// se for uma chave abrindo | |
if(c=='{') qtd++; // incremento o valor de qtd em 1 unidade | |
// se for uma chave fechando | |
if(c=='}'){ | |
// checo se há chaves abertas | |
if(qtd<1) erro=true; | |
// e diminuo o valor de qtd em 1 unidade | |
qtd--; | |
} | |
} | |
// se fechei chaves que não haviam sido abertas ou ainda há chaves abertas | |
if(erro||qtd) printf("N\n"); // há erro de compilação | |
// caso contrário, não há erro nas chaves do código | |
else printf("S\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment