Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Online C compiler to run C program online
- #include <stdio.h>
- typedef struct{
- int idade;
- float altura;
- char nome [50];
- float tag;
- //tag = altura*idade*strlen(nome);
- } crianca;
- int main() {
- // Write C code here
- int n, m, x;
- printf("digite o numero de crias: ");
- scanf("%d", &n);
- printf("\nquantos vc quer levar: ");
- scanf("%d", &m);
- printf("\nqual o numero mágico: ");
- scanf("%d", &x);
- crianca orfanato[n];
- int indiceSorte [m];
- int diff[n];
- int tag[n];
- for(int i = 0 ; i < n ; i++){
- scanf("%s %d %f", orfanato[i].nome&orfanato[i].idade, &orfanato[i].altura);
- orfanato[i].tag = orfanato[i].altura*orfanato[i].idade*strlen(orfanato[i].nome);
- }
- // armazenei as diferencas entre cada tag da criança e o numero mágico
- for(int i = 0 ; i < n ; i++){
- diff[i] = x - orfanato[i].tag
- tag[i] = 100000;
- if(diff[i] < 0) diff[i] = -diff[i];
- }
- // agora eu vou pegar as M menores diferencas e armazenar os indices deles no array lá;
- int min = 100000;
- for(int i = 0 ; i < m ; i++){
- for(int j = 0; j < n ; j++){
- if(tag[i] == j){
- continue;
- }
- if(diff[j] < min){
- min = diff[j];
- tag[i] = j;
- indiceSorte[i] = j
- }
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment