#include <istream> #include <iostream> #include <string.h> class KarCaseInput { private: int n; int m; int* myDecks; int* oponentDecks; public: KarCaseInput(int n, int m) { this->n = n; this->m = m; this->myDecks = new int[n]; memset(this->myDecks, 0, n*sizeof(int)); this->oponentDecks = new int[n]; memset(this->oponentDecks, 0, n*sizeof(int)); } virtual ~KarCaseInput() { delete[] this->myDecks; delete[] this->oponentDecks; } int getN() { return n; } int getM() { return m; } void incOponentDeckLooses(int deckNo) { this->oponentDecks[deckNo-1]++; } void incMyDeckLooses(int deckNo) { this->myDecks[deckNo-1]++; } int getOponentDeckLooses(int deckNo) { return this->oponentDecks[deckNo-1]; } int getMyDeckLooses(int deckNo) { return this->myDecks[deckNo-1]; } }; void sample(KarCaseInput* i) { i->getM(); i->getN(); i->getMyDeckLooses(1); i->getOponentDeckLooses(1); } bool isLeftDeckWinning(char relation) { if(relation == '>') { return true; } else { return false; } } KarCaseInput* karParseInput(std::istream &is) { int n = 0; int m = 0; is >> n; is >> m; KarCaseInput* result = new KarCaseInput(n, m); for(int i = 0; i < m; i++) { int left = 0; int right = 0; char relation = '\0'; is >> left; is >> relation; is >> right; if(isLeftDeckWinning(relation)) { result->incOponentDeckLooses(right); } else { result->incMyDeckLooses(left); } } return result; } bool karIsOponentStrategyLoosing(KarCaseInput* input) { for(int i = 1; i <= input->getN(); i++) { if(input->getOponentDeckLooses(i) == input->getN()) { return true; } } return false; } bool karIsMyStrategyLoosing(KarCaseInput* input) { for(int i = 1; i <= input->getN(); i++) { if(input->getMyDeckLooses(i) == input->getN()) { return true; } } return false; } void karComputeResult(KarCaseInput* input, std::ostream &ostream) { if(input->getM() < input->getN()) { ostream << "REMIS"; } else { if(karIsMyStrategyLoosing(input)) { ostream << "PRZEGRANA"; } else if(karIsOponentStrategyLoosing(input)) { ostream << "WYGRANA"; } else { ostream << "REMIS"; } } ostream << std::endl; } void runKar(std::istream &is, std::ostream &os) { int num = 0; is >> num; for(int i = 0; i < num; i++) { KarCaseInput* input = karParseInput(is); karComputeResult(input, os); delete input; } } int main(int argc, char* argv[]) { runKar(std::cin, std::cout); }
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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | #include <istream> #include <iostream> #include <string.h> class KarCaseInput { private: int n; int m; int* myDecks; int* oponentDecks; public: KarCaseInput(int n, int m) { this->n = n; this->m = m; this->myDecks = new int[n]; memset(this->myDecks, 0, n*sizeof(int)); this->oponentDecks = new int[n]; memset(this->oponentDecks, 0, n*sizeof(int)); } virtual ~KarCaseInput() { delete[] this->myDecks; delete[] this->oponentDecks; } int getN() { return n; } int getM() { return m; } void incOponentDeckLooses(int deckNo) { this->oponentDecks[deckNo-1]++; } void incMyDeckLooses(int deckNo) { this->myDecks[deckNo-1]++; } int getOponentDeckLooses(int deckNo) { return this->oponentDecks[deckNo-1]; } int getMyDeckLooses(int deckNo) { return this->myDecks[deckNo-1]; } }; void sample(KarCaseInput* i) { i->getM(); i->getN(); i->getMyDeckLooses(1); i->getOponentDeckLooses(1); } bool isLeftDeckWinning(char relation) { if(relation == '>') { return true; } else { return false; } } KarCaseInput* karParseInput(std::istream &is) { int n = 0; int m = 0; is >> n; is >> m; KarCaseInput* result = new KarCaseInput(n, m); for(int i = 0; i < m; i++) { int left = 0; int right = 0; char relation = '\0'; is >> left; is >> relation; is >> right; if(isLeftDeckWinning(relation)) { result->incOponentDeckLooses(right); } else { result->incMyDeckLooses(left); } } return result; } bool karIsOponentStrategyLoosing(KarCaseInput* input) { for(int i = 1; i <= input->getN(); i++) { if(input->getOponentDeckLooses(i) == input->getN()) { return true; } } return false; } bool karIsMyStrategyLoosing(KarCaseInput* input) { for(int i = 1; i <= input->getN(); i++) { if(input->getMyDeckLooses(i) == input->getN()) { return true; } } return false; } void karComputeResult(KarCaseInput* input, std::ostream &ostream) { if(input->getM() < input->getN()) { ostream << "REMIS"; } else { if(karIsMyStrategyLoosing(input)) { ostream << "PRZEGRANA"; } else if(karIsOponentStrategyLoosing(input)) { ostream << "WYGRANA"; } else { ostream << "REMIS"; } } ostream << std::endl; } void runKar(std::istream &is, std::ostream &os) { int num = 0; is >> num; for(int i = 0; i < num; i++) { KarCaseInput* input = karParseInput(is); karComputeResult(input, os); delete input; } } int main(int argc, char* argv[]) { runKar(std::cin, std::cout); } |