that_one_nigga_you_k

adocao 2

Jul 21st, 2023
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.51 KB | None | 0 0
  1. // Online C compiler to run C program online
  2. #include <stdio.h>
  3.  
  4. typedef struct{
  5.     int idade;
  6.     float altura;
  7.     char nome [50];
  8.     float tag;
  9.    
  10.     //tag = altura*idade*strlen(nome);
  11.    
  12. } crianca;
  13.  
  14. int main() {
  15.     // Write C code here
  16.     int n, m, x;
  17.    
  18.     printf("digite o numero de crias: ");
  19.     scanf("%d", &n);
  20.     printf("\nquantos vc quer levar: ");
  21.     scanf("%d", &m);
  22.     printf("\nqual o numero mágico: ");
  23.     scanf("%d", &x);
  24.    
  25.     crianca orfanato[n];
  26.     int indiceSorte [m];
  27.     int diff[n];
  28.     int tag[n];
  29.    
  30.     for(int i = 0 ; i < n ; i++){
  31.         scanf("%s %d %f", orfanato[i].nome&orfanato[i].idade, &orfanato[i].altura);
  32.         orfanato[i].tag = orfanato[i].altura*orfanato[i].idade*strlen(orfanato[i].nome);
  33.     }
  34.    
  35.     // armazenei as diferencas entre cada tag da criança e o numero mágico
  36.    
  37.     for(int i = 0 ; i < n ; i++){
  38.         diff[i] = x - orfanato[i].tag
  39.         tag[i] = 100000;
  40.        
  41.         if(diff[i] < 0) diff[i] = -diff[i];
  42.        
  43.     }
  44.    
  45.     // agora eu vou pegar as M menores diferencas e armazenar os indices deles no array lá;
  46.     int min = 100000;
  47.      
  48.    
  49.     for(int i = 0 ; i < m ; i++){
  50.         for(int j = 0; j < n ; j++){
  51.             if(tag[i] == j){
  52.                 continue;
  53.             }
  54.            
  55.             if(diff[j] < min){
  56.                min = diff[j];
  57.                tag[i] = j;
  58.                indiceSorte[i] = j
  59.             }
  60.         }
  61.     }
  62.    
  63.    
  64.    
  65.     return 0;
  66. }
Add Comment
Please, Sign In to add comment