Difference between revisions of "Solução: Problema do professor de terceiro ano (Márcio Trindade)"
From AdonaiMedrado.Pro.Br
(New page: <code lang="c"> #include<stdio.h> int main(void) { struct student { char nome[41]; int resp; int nota; }; struct student aluno[100], troca; int i,j, gab, n, bin1, acum; flo...) |
|||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
<code lang="c"> | <code lang="c"> | ||
#include<stdio.h> | #include<stdio.h> | ||
− | + | #include <stdlib.h> | |
+ | #include<string.h> | ||
int main(void) | int main(void) | ||
{ | { | ||
− | + | struct estudante | |
− | + | { | |
− | + | char nome[51]; | |
− | + | int resp; | |
− | + | int nota; | |
− | + | }; | |
− | + | int comparar(const void *a, const void *b) | |
− | + | { | |
− | + | return (*(struct estudante *)a).nota-(*(struct estudante *)b).nota; | |
− | + | } | |
− | + | struct estudante aluno[100], troca; | |
− | + | int i,j, gab, n, bin1,quantm=0,minipont=0,maxpont=0, acum; | |
− | + | float med=0; | |
− | + | scanf("%d",&gab); | |
− | + | scanf("%d",&n); | |
− | + | for(i=0;i<n;i++) | |
− | + | { | |
− | + | scanf("%s",aluno[i].nome); | |
− | + | scanf("%d",&(aluno[i].resp)); | |
− | + | bin1 = gab & aluno[i].resp; | |
− | + | acum=0; | |
− | + | for(j=0;j<7;j++) | |
− | + | acum += ((bin1>>j)&1); | |
− | + | aluno[i].nota = acum; | |
− | + | if(maxpont<acum) | |
− | + | maxpont=acum; | |
− | + | med+=acum; | |
− | + | } | |
− | + | qsort(aluno,n,sizeof(struct estudante),comparar); | |
− | + | printf("%d ",aluno[0].nota); | |
− | + | for(i=0;i<=n;i++) | |
− | + | if(minipont==aluno[i].nota) | |
− | + | printf("%s ", aluno[i].nome); | |
− | + | printf("\n%d ", maxpont); | |
− | + | for(i=0;i<=n;i++) | |
− | + | if(aluno[i].nota==maxpont) | |
− | + | {quantm+=1; | |
− | + | printf("%s ",aluno[i].nome); | |
− | + | }printf("\n%.1f", med/n); | |
− | + | printf("\n\n"); | |
− | + | system("PAUSE"); | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
return 0; | return 0; | ||
} | } | ||
− | |||
</code> | </code> |
Latest revision as of 00:56, 8 June 2009
#include<stdio.h> #include <stdlib.h> #include<string.h> int main(void) { struct estudante { char nome[51]; int resp; int nota; }; int comparar(const void *a, const void *b) { return (*(struct estudante *)a).nota-(*(struct estudante *)b).nota; } struct estudante aluno[100], troca; int i,j, gab, n, bin1,quantm=0,minipont=0,maxpont=0, acum; float med=0; scanf("%d",&gab); scanf("%d",&n); for(i=0;i<n;i++) { scanf("%s",aluno[i].nome); scanf("%d",&(aluno[i].resp)); bin1 = gab & aluno[i].resp; acum=0; for(j=0;j<7;j++) acum += ((bin1>>j)&1); aluno[i].nota = acum; if(maxpont<acum) maxpont=acum; med+=acum; } qsort(aluno,n,sizeof(struct estudante),comparar); printf("%d ",aluno[0].nota); for(i=0;i<=n;i++) if(minipont==aluno[i].nota) printf("%s ", aluno[i].nome); printf("\n%d ", maxpont); for(i=0;i<=n;i++) if(aluno[i].nota==maxpont) {quantm+=1; printf("%s ",aluno[i].nome); }printf("\n%.1f", med/n); printf("\n\n"); system("PAUSE"); return 0; }