Advertisement
Kalhnyxtakias

Untitled

Jan 27th, 2021
855
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.53 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "exam.h"
  5.  
  6. int find(char name[], struct single function_array[N]){
  7.    
  8.     int i;
  9.  
  10.     for(i=0; i<N; i++){
  11.         if(strcmp(name, function_array[i].name) == 0){
  12.             return function_array[i].single_score;
  13.         }
  14.     }
  15.    
  16.     return -1;
  17. }
  18.  
  19. void calc(struct team function_array[N/2]){
  20.     int i;
  21.  
  22.     for(i=0; i<N/2; i++){
  23.        
  24.         function_array[i].member1->total_score = (function_array[i].member1->single_score + function_array[i].team_score)/2.0;
  25.        
  26.         function_array[i].member2->total_score = (function_array[i].member2->single_score + function_array[i].team_score)/2.0;
  27.     }
  28. }
  29.  
  30. void rank(struct single singles_array[N], struct single *pointers_array[N]){
  31.  
  32.     struct single* max_pointer;
  33.     int max;
  34.     int pointer_count;
  35.     int i,k,flag;
  36.  
  37.     for(pointer_count = 0; pointer_count < N; pointer_count++){
  38.         max_pointer  = &singles_array[0];
  39.         max  = -1;
  40.         for(i = 0; i<N; i++){
  41.             if (singles_array[i].total_score > max){
  42.                 flag = 1;
  43.                 for(k=0; k<N; k++){
  44.                     if(&singles_array[i] == pointers_array[k]){
  45.                         flag = 0;
  46.                         break;
  47.                     }
  48.                 }
  49.                 if(flag){
  50.                     max_pointer = &singles_array[i];
  51.                 }
  52.             }
  53.         }
  54.     pointers_array[pointer_count] = max_pointer;  
  55.     }
  56. }
  57.  
  58.  
  59.  
  60. int main(int argc, char* argv[]){
  61.    
  62.     struct single singles_array[N];
  63.     struct team teams_array[N/2];
  64.     struct single * pointers_to_singles_array[N];
  65.  
  66.     init(singles_array, teams_array);
  67.     print_all(teams_array);
  68.  
  69.     if(argc == 1 || argc > 3){
  70.         return 42;
  71.     }
  72.  
  73.     if(strcmp(argv[1], "f") == 0){
  74.         if(argc != 3){
  75.             return 42;
  76.         }
  77.         else{
  78.             printf("%d\n", find(argv[2],singles_array));
  79.         }
  80.     }
  81.     else if(strcmp(argv[1], "c") == 0){
  82.         if (argc != 2){
  83.             return 42;
  84.         }
  85.         else{
  86.             calc(teams_array);
  87.             print_all(teams_array);
  88.         }
  89.     }
  90.     else if( strcmp(argv[1], "r") == 0){
  91.         if(argc!= 2){
  92.             return 42;
  93.         }
  94.         else{
  95.             calc(teams_array);
  96.             rank(singles_array,pointers_to_singles_array);
  97.             print_rank(pointers_to_singles_array);
  98.             print_all(teams_array);
  99.         }
  100.     }
  101.     else{
  102.         return 42;
  103.     }
  104.  
  105.  
  106.  
  107.     return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement