#include <cstdio> #include <numeric> using namespace std; char* ALGOSIA = "Algosia"; char* BAJTEK = "Bajtek"; char* REMIS = "remis"; const int NUMBER_OF_TASKS = 18; const int MAX_SCORE = 10; char* get_result( int algosia_scores[], int algosia_score_counts[], int algosia_sum, int bajtek_scores[], int bajtek_score_counts[], int bajtek_sum ) { if (algosia_sum > bajtek_sum) { return ALGOSIA; } else if (bajtek_sum > algosia_sum) { return BAJTEK; } else { for (int i = MAX_SCORE; i > 0; i--) { // printf("%d %d %d\n", i, algosia_score_counts[i], bajtek_score_counts[i]); if (algosia_score_counts[i] > bajtek_score_counts[i]) { return ALGOSIA; } else if (algosia_score_counts[i] < bajtek_score_counts[i]) { return BAJTEK; } } } return REMIS; } void read_scores(int scores_array[]) { for (int i = 0; i < NUMBER_OF_TASKS; i++) { scanf("%d", &scores_array[i]); } } int main() { int algosia_scores[NUMBER_OF_TASKS]; int algosia_score_counts[MAX_SCORE + 1] = { 0 }; int bajtek_scores[NUMBER_OF_TASKS]; int bajtek_score_counts[MAX_SCORE + 1] = { 0 }; for (int i = 0; i < 11; i++) { algosia_score_counts[i] = 0; bajtek_score_counts[i] = 0; } read_scores(algosia_scores); read_scores(bajtek_scores); int algosia_sum = accumulate(algosia_scores, algosia_scores + NUMBER_OF_TASKS, 0); int bajtek_sum = accumulate(bajtek_scores, bajtek_scores + NUMBER_OF_TASKS, 0); for (int score : algosia_scores) { algosia_score_counts[score]++; } for (int score : bajtek_scores) { bajtek_score_counts[score]++; } printf("%s\n", get_result( algosia_scores, algosia_score_counts, algosia_sum, bajtek_scores, bajtek_score_counts, bajtek_sum )); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | #include <cstdio> #include <numeric> using namespace std; char* ALGOSIA = "Algosia"; char* BAJTEK = "Bajtek"; char* REMIS = "remis"; const int NUMBER_OF_TASKS = 18; const int MAX_SCORE = 10; char* get_result( int algosia_scores[], int algosia_score_counts[], int algosia_sum, int bajtek_scores[], int bajtek_score_counts[], int bajtek_sum ) { if (algosia_sum > bajtek_sum) { return ALGOSIA; } else if (bajtek_sum > algosia_sum) { return BAJTEK; } else { for (int i = MAX_SCORE; i > 0; i--) { // printf("%d %d %d\n", i, algosia_score_counts[i], bajtek_score_counts[i]); if (algosia_score_counts[i] > bajtek_score_counts[i]) { return ALGOSIA; } else if (algosia_score_counts[i] < bajtek_score_counts[i]) { return BAJTEK; } } } return REMIS; } void read_scores(int scores_array[]) { for (int i = 0; i < NUMBER_OF_TASKS; i++) { scanf("%d", &scores_array[i]); } } int main() { int algosia_scores[NUMBER_OF_TASKS]; int algosia_score_counts[MAX_SCORE + 1] = { 0 }; int bajtek_scores[NUMBER_OF_TASKS]; int bajtek_score_counts[MAX_SCORE + 1] = { 0 }; for (int i = 0; i < 11; i++) { algosia_score_counts[i] = 0; bajtek_score_counts[i] = 0; } read_scores(algosia_scores); read_scores(bajtek_scores); int algosia_sum = accumulate(algosia_scores, algosia_scores + NUMBER_OF_TASKS, 0); int bajtek_sum = accumulate(bajtek_scores, bajtek_scores + NUMBER_OF_TASKS, 0); for (int score : algosia_scores) { algosia_score_counts[score]++; } for (int score : bajtek_scores) { bajtek_score_counts[score]++; } printf("%s\n", get_result( algosia_scores, algosia_score_counts, algosia_sum, bajtek_scores, bajtek_score_counts, bajtek_sum )); } |