Last active
August 29, 2015 14:19
-
-
Save rogerioagjr/4fa066dee49d39a6a38d to your computer and use it in GitHub Desktop.
Contando Estrelas
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
#include <cstdio> // printf e scanf | |
#include <cstring> // memset | |
#define MAXN 10100 // limite de N | |
int n, r, controle, vetor[MAXN]; // declaração de variáveis | |
int main(){ | |
while(scanf("%d %d", &n, &r)!=EOF){ // leia até o fim de arquivo | |
memset(vetor, 0, sizeof(vetor)); // zere o vetor | |
for(int i=1; i<=r; i++){ // para cada valor dado | |
int estrela; | |
scanf("%d", &estrela); // leia o inteiro | |
vetor[estrela]=1; // e marque que ele apareceu | |
} | |
controle=0; // zere controle | |
for(int i=1; i<=n; i++){ // para cada estrela | |
if(vetor[i]==0){ // se ela não foi marcada | |
printf("%d ", i); // imprima seu índice | |
controle=1; // e faça controle receber 1 | |
} | |
} | |
if(controle==0) printf("*"); // se controle for 0, então nenhuma estrela foi impressa e devemos imprimir "*" | |
printf("\n"); // imprima a quebra de linha | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment