#include <iostream>
#include <map>
#ifdef DEBUG
#define DEBUG_LOG(x) do { \
std::cerr << x << std::endl;\
} while (0)
#else
#define DEBUG_LOG(x) do { \
} while (0)
#endif
struct LetterStat
{
uint64_t evens;
uint64_t odds;
LetterStat(uint64_t e=0, uint64_t o=0)
: evens(e)
, odds(o)
{}
friend std::ostream& operator<<(std::ostream& stream, LetterStat const& stat)
{
stream << "{e : ";
stream << stat.evens;
stream << ", o :";
stream << stat.odds << "}";
return stream;
}
bool operator==(LetterStat const& rhs) const
{
return (evens == rhs.evens) && (odds == rhs.odds);
}
bool operator!=(LetterStat const& rhs) const
{
return !((*this) == rhs);
}
};
using StatMap_t = std::map<char,LetterStat>;
void LoadMap(std::istream& input, StatMap_t& sm, uint64_t num)
{
char l;
for(uint64_t i =0; i<num; i++)
{
input >> l;
if (sm.find(l) == sm.end())
{
sm.emplace(l, LetterStat());
}
if (i & 0x01)
{
sm[l].odds += 1;
}
else
{
sm[l].evens += 1;
}
}
}
void Run(std::istream& input, std::ostream& output)
{
uint64_t num = 0;
input >> num;
StatMap_t m1{};
StatMap_t m2{};
LoadMap(input, m1, num);
LoadMap(input, m2, num);
if (m1 == m2)
{
output << "TAK";
}
else
{
output << "NIE";
}
output << std::endl;
}
#ifndef DEBUG
int main(int argc, char* argv[])
#else
int main_(int argc, char* argv[])
#endif
{
::Run(std::cin, std::cout);
return 0;
}
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 | #include <iostream> #include <map> #ifdef DEBUG #define DEBUG_LOG(x) do { \ std::cerr << x << std::endl;\ } while (0) #else #define DEBUG_LOG(x) do { \ } while (0) #endif struct LetterStat { uint64_t evens; uint64_t odds; LetterStat(uint64_t e=0, uint64_t o=0) : evens(e) , odds(o) {} friend std::ostream& operator<<(std::ostream& stream, LetterStat const& stat) { stream << "{e : "; stream << stat.evens; stream << ", o :"; stream << stat.odds << "}"; return stream; } bool operator==(LetterStat const& rhs) const { return (evens == rhs.evens) && (odds == rhs.odds); } bool operator!=(LetterStat const& rhs) const { return !((*this) == rhs); } }; using StatMap_t = std::map<char,LetterStat>; void LoadMap(std::istream& input, StatMap_t& sm, uint64_t num) { char l; for(uint64_t i =0; i<num; i++) { input >> l; if (sm.find(l) == sm.end()) { sm.emplace(l, LetterStat()); } if (i & 0x01) { sm[l].odds += 1; } else { sm[l].evens += 1; } } } void Run(std::istream& input, std::ostream& output) { uint64_t num = 0; input >> num; StatMap_t m1{}; StatMap_t m2{}; LoadMap(input, m1, num); LoadMap(input, m2, num); if (m1 == m2) { output << "TAK"; } else { output << "NIE"; } output << std::endl; } #ifndef DEBUG int main(int argc, char* argv[]) #else int main_(int argc, char* argv[]) #endif { ::Run(std::cin, std::cout); return 0; } |
English