#include <iostream>
#include <vector>
using namespace std;
bool isPalindrome(const string& s, int k)
{
int n = s.size();
for (int len = k + 1; len <= k + 2; len++)
{
if (len > n) continue;
bool pal = true;
for (int i = 0; i < len / 2; i++)
{
if (s[n - len + i] != s[n - 1 - i])
{
pal = false;
break;
}
}
if (pal) return true;
}
return false;
}
int main()
{
int t;
cin >> t;
vector<pair<int, int>> tests(t, pair<int, int>(0, 0));
for (int i = 0; i < t; i++)
{
cin >> tests[i].first >> tests[i].second;
}
for (int i = 0; i < t; i++)
{
string res = "";
bool shouldCheckPalindrome = true;
for (int j = 0; j < tests[i].first; j++)
{
bool placed = false;
for (char c : {'A', 'P'})
{
res.push_back(c);
if (!isPalindrome(res, tests[i].second))
{
placed = true;
break;
}
res.pop_back();
}
if (!placed)
{
cout << "NIE\n";
shouldCheckPalindrome = false;
break;
}
}
bool ok = false;
if(shouldCheckPalindrome)
{
for (int j = 0; j + tests[i].second <= tests[i].first; j++)
{
bool palindrome = true;
for (int k = 0; k < tests[i].second / 2; k++)
{
if (res[j + k] != res[j + tests[i].second - 1 - k])
{
palindrome = false;
break;
}
}
if (palindrome)
{
ok = true;
break;
}
}
if (!ok)
{
cout << "NIE\n";
}
}
if (ok)
{
cout << res << "\n";
}
}
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 | #include <iostream> #include <vector> using namespace std; bool isPalindrome(const string& s, int k) { int n = s.size(); for (int len = k + 1; len <= k + 2; len++) { if (len > n) continue; bool pal = true; for (int i = 0; i < len / 2; i++) { if (s[n - len + i] != s[n - 1 - i]) { pal = false; break; } } if (pal) return true; } return false; } int main() { int t; cin >> t; vector<pair<int, int>> tests(t, pair<int, int>(0, 0)); for (int i = 0; i < t; i++) { cin >> tests[i].first >> tests[i].second; } for (int i = 0; i < t; i++) { string res = ""; bool shouldCheckPalindrome = true; for (int j = 0; j < tests[i].first; j++) { bool placed = false; for (char c : {'A', 'P'}) { res.push_back(c); if (!isPalindrome(res, tests[i].second)) { placed = true; break; } res.pop_back(); } if (!placed) { cout << "NIE\n"; shouldCheckPalindrome = false; break; } } bool ok = false; if(shouldCheckPalindrome) { for (int j = 0; j + tests[i].second <= tests[i].first; j++) { bool palindrome = true; for (int k = 0; k < tests[i].second / 2; k++) { if (res[j + k] != res[j + tests[i].second - 1 - k]) { palindrome = false; break; } } if (palindrome) { ok = true; break; } } if (!ok) { cout << "NIE\n"; } } if (ok) { cout << res << "\n"; } } return 0; } |
English