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...) |
|||
Line 1: | Line 1: | ||
<code lang="c"> | <code lang="c"> | ||
#include<stdio.h> | #include<stdio.h> | ||
− | + | ||
− | + | ||
int main(void) | int main(void) | ||
{ | { | ||
struct student | struct student | ||
{ | { | ||
− | char nome[ | + | char nome[51]; |
int resp; | int resp; | ||
int nota; | int nota; | ||
}; | }; | ||
− | + | ||
struct student aluno[100], troca; | struct student aluno[100], troca; | ||
int i,j, gab, n, bin1, acum; | int i,j, gab, n, bin1, acum; | ||
− | float med; | + | float med=0; |
− | + | ||
scanf("%d",&gab); | scanf("%d",&gab); | ||
scanf("%d",&n); | scanf("%d",&n); | ||
Line 21: | Line 21: | ||
{ | { | ||
scanf("%s",aluno[i].nome); | scanf("%s",aluno[i].nome); | ||
− | scanf("%d",&(aluno[i].resp); | + | scanf("%d",&(aluno[i].resp)); |
bin1 = gab&aluno[i].resp; | bin1 = gab&aluno[i].resp; | ||
acum=0; | acum=0; | ||
Line 27: | Line 27: | ||
acum += ((bin1>>j)&1); | acum += ((bin1>>j)&1); | ||
aluno[i].nota = acum; | aluno[i].nota = acum; | ||
− | med+=acum | + | med+=acum; |
} | } | ||
− | + | ||
− | for(i | + | for(i=0;i<n;i++) |
{ | { | ||
for(j=i+1;j<n;j++) | for(j=i+1;j<n;j++) | ||
Line 42: | Line 42: | ||
} | } | ||
} | } | ||
− | + | ||
− | printf("%d | + | printf("\n%d", aluno[i].nota); |
for(j=i;j>=0;j--) | for(j=i;j>=0;j--) | ||
if(aluno[i].nota==aluno[i].nota) | if(aluno[i].nota==aluno[i].nota) | ||
− | printf("%s",aluno[j].nome); | + | printf("\t%s",aluno[j].nome); |
− | + | ||
− | printf(" | + | printf("\n%d", aluno[0].nota); |
for(j=0;j<n;j++) | for(j=0;j<n;j++) | ||
− | + | ||
− | + | ||
if(aluno[j].nota==aluno[0].nota) | if(aluno[j].nota==aluno[0].nota) | ||
− | printf("%s",aluno[j].nome); | + | printf("\t%s",aluno[j].nome); |
− | + | ||
return 0; | return 0; | ||
} | } | ||
+ | |||
</code> | </code> |
Revision as of 18:43, 5 June 2009
#include<stdio.h> int main(void) { struct student { char nome[51]; int resp; int nota; }; struct student aluno[100], troca; int i,j, gab, n, bin1, 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; med+=acum; } for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(aluno[i].nota>aluno[j].nota) { troca=aluno[i]; aluno[i]=aluno[j]; aluno[j]=troca; } } } printf("\n%d", aluno[i].nota); for(j=i;j>=0;j--) if(aluno[i].nota==aluno[i].nota) printf("\t%s",aluno[j].nome); printf("\n%d", aluno[0].nota); for(j=0;j<n;j++) if(aluno[j].nota==aluno[0].nota) printf("\t%s",aluno[j].nome); return 0; }