#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
typedef long long lLong;
typedef unsigned long uLong;
typedef unsigned long long ulLong;
typedef unsigned int uInt;
typedef unsigned char Byte;
typedef struct std::vector<std::pair<int, int>> VPI;
using namespace std;
const int MAX_N = 300002;
class PrzypadekTestowy
{
private:
FILE* _input;
inline void WczytajInt(int* value)
{
auto _ = fscanf(_input, "%d", value);
}
inline void WczytajChar(char* value)
{
auto _ = fscanf(_input, "%c", value);
}
inline void WyczyscNewLine()
{
auto _ = fscanf(_input, "\n");
}
public:
PrzypadekTestowy() :_input(stdin)
{
}
PrzypadekTestowy(FILE* input)
{
_input = input;
}
inline void Wykonaj()
{
int n = 0;
WczytajInt(&n);
WyczyscNewLine();
VPI bitus = VPI(26, {0,0}); //rozmiar rowny liczbie mozliwych zabawek
for (int i = 0; i < n; i++)
{
char c;
WczytajChar(&c);
auto p = &bitus[c - 'a'];
if (i % 2 == 0) p->first++;
else p->second++;
}
WyczyscNewLine();
for (int i = 0; i < n; i++)
{
char c;
WczytajChar(&c);
auto p = &bitus[c - 'a'];
if (i % 2 == 0) p->first--;
else p->second--;
}
bool czyOk = true;
for (auto p : bitus)
{
if (p.first || p.second)
{
czyOk = false;
break;
}
}
printf("%s\n", (czyOk ? "TAK" : "NIE"));
}
};
int main(int argc, char** argv)
{
FILE* in = stdin;
if (argc > 1)
{
in = fopen(argv[1], "rt");
if (NULL == in)
{
in = stdin;
}
}
PrzypadekTestowy* p = new PrzypadekTestowy(in);
p->Wykonaj();
fflush(in);
fclose(in);
delete(p);
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 98 99 100 101 102 103 104 105 106 | #define _CRT_SECURE_NO_WARNINGS #include <cstdio> #include <stdio.h> #include <iostream> #include <string.h> #include <math.h> #include <algorithm> #include <vector> typedef long long lLong; typedef unsigned long uLong; typedef unsigned long long ulLong; typedef unsigned int uInt; typedef unsigned char Byte; typedef struct std::vector<std::pair<int, int>> VPI; using namespace std; const int MAX_N = 300002; class PrzypadekTestowy { private: FILE* _input; inline void WczytajInt(int* value) { auto _ = fscanf(_input, "%d", value); } inline void WczytajChar(char* value) { auto _ = fscanf(_input, "%c", value); } inline void WyczyscNewLine() { auto _ = fscanf(_input, "\n"); } public: PrzypadekTestowy() :_input(stdin) { } PrzypadekTestowy(FILE* input) { _input = input; } inline void Wykonaj() { int n = 0; WczytajInt(&n); WyczyscNewLine(); VPI bitus = VPI(26, {0,0}); //rozmiar rowny liczbie mozliwych zabawek for (int i = 0; i < n; i++) { char c; WczytajChar(&c); auto p = &bitus[c - 'a']; if (i % 2 == 0) p->first++; else p->second++; } WyczyscNewLine(); for (int i = 0; i < n; i++) { char c; WczytajChar(&c); auto p = &bitus[c - 'a']; if (i % 2 == 0) p->first--; else p->second--; } bool czyOk = true; for (auto p : bitus) { if (p.first || p.second) { czyOk = false; break; } } printf("%s\n", (czyOk ? "TAK" : "NIE")); } }; int main(int argc, char** argv) { FILE* in = stdin; if (argc > 1) { in = fopen(argv[1], "rt"); if (NULL == in) { in = stdin; } } PrzypadekTestowy* p = new PrzypadekTestowy(in); p->Wykonaj(); fflush(in); fclose(in); delete(p); return 0; } |
English