Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "exam.h"
- int find(char name[], struct single function_array[N]){
- int i;
- for(i=0; i<N; i++){
- if(strcmp(name, function_array[i].name) == 0){
- return function_array[i].single_score;
- }
- }
- return -1;
- }
- void calc(struct team function_array[N/2]){
- int i;
- for(i=0; i<N/2; i++){
- function_array[i].member1->total_score = (function_array[i].member1->single_score + function_array[i].team_score)/2.0;
- function_array[i].member2->total_score = (function_array[i].member2->single_score + function_array[i].team_score)/2.0;
- }
- }
- void rank(struct single singles_array[N], struct single *pointers_array[N]){
- struct single* max_pointer;
- int max;
- int pointer_count;
- int i,k,flag;
- for(pointer_count = 0; pointer_count < N; pointer_count++){
- max_pointer = &singles_array[0];
- max = -1;
- for(i = 0; i<N; i++){
- if (singles_array[i].total_score > max){
- flag = 1;
- for(k=0; k<N; k++){
- if(&singles_array[i] == pointers_array[k]){
- flag = 0;
- break;
- }
- }
- if(flag){
- max_pointer = &singles_array[i];
- }
- }
- }
- pointers_array[pointer_count] = max_pointer;
- }
- }
- int main(int argc, char* argv[]){
- struct single singles_array[N];
- struct team teams_array[N/2];
- struct single * pointers_to_singles_array[N];
- init(singles_array, teams_array);
- print_all(teams_array);
- if(argc == 1 || argc > 3){
- return 42;
- }
- if(strcmp(argv[1], "f") == 0){
- if(argc != 3){
- return 42;
- }
- else{
- printf("%d\n", find(argv[2],singles_array));
- }
- }
- else if(strcmp(argv[1], "c") == 0){
- if (argc != 2){
- return 42;
- }
- else{
- calc(teams_array);
- print_all(teams_array);
- }
- }
- else if( strcmp(argv[1], "r") == 0){
- if(argc!= 2){
- return 42;
- }
- else{
- calc(teams_array);
- rank(singles_array,pointers_to_singles_array);
- print_rank(pointers_to_singles_array);
- print_all(teams_array);
- }
- }
- else{
- return 42;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement