1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| int main(void)
{
int nLig, nCol;
/* Lit les nombres de ligne et colonnes */
int nScanned = scanf("%d %d", &nLig, &nCol);
purge();
if(nScanned!=2)
{
puts("Erreur");
return EXIT_FAILURE;
}
/* Lit les arbres */
{
int nArbres = 0;
int lig, col;
for(lig=0 ; lig<nLig ; lig++)
{
for(col=0 ; col<nCol ; col++)
{
int c = getchar();
if(c==EOF || c=='\n')
{
/* Erreur, ou ligne trop courte */
puts("Erreur");
return EXIT_FAILURE;
}
if(c=='#')
nArbres++;
}
/* Lit la fin de la ligne, ignore les caractères en trop */
purge();
}
/*maintenant, on a le nombre d'arbres*/
printf("Arbres : %d\n", nArbres);
}
return EXIT_SUCCESS;
} |