Skip to content

Instantly share code, notes, and snippets.

@rogerioagjr
Last active August 29, 2015 14:19
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/4fa066dee49d39a6a38d to your computer and use it in GitHub Desktop.
Save rogerioagjr/4fa066dee49d39a6a38d to your computer and use it in GitHub Desktop.
Contando Estrelas
#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