#include <cstdio>
#define MAX_SIZE 3000000
char palindrom[MAX_SIZE];
int counter = 0;
// A function to check if a string str is palindrome
void isPalindrome()
{
// Start from leftmost and rightmost corners of str
int l = 0;
int h = counter - 1;
// Keep comparing characters while they are same
while (h > l)
{
if (palindrom[l++] != palindrom[h--])
{
printf("NIE");
return;
}
}
printf("TAK");
}
int main() {
char ch;
int placeHolder;
scanf("%d", &placeHolder);
getchar();
while ((ch = getchar()) != '\n') {
palindrom[counter] = ch;
++counter;
}
isPalindrome();
/*
To nie działa bo myslalem ze da sie zapisac litery a-z (26 znaków) na 4 bitach lecz jednak potrzebne jest 5 bitów
int ch;
int maska = 0b1111;
while ((ch = getchar()) != '\n') {
ch = ch - 'a';
//ch = ch & maska;
if (counter % 2 == 1)
ch <<= 3;
palindrom[counter / 2] = palindrom[counter / 2] | ch;
++counter;
}
for (int i = 0; i < counter; i++)
{
ch = palindrom[i / 2];
if (i % 2 == 1)
{
ch = ch >> 4;
}
else {
ch = ch & maska;
}
ch += 'a';
printf("%c", ch);
}
*/
/*
int l = 0;
int h = counter - 1;
// Keep comparing characters while they are same
while (h > l)
{
if (palindrom[l++] != palindrom[h--])
{
printf("%s is Not Palindrome", palindrom);
return 0;
}
}
printf("%s is palindrome", palindrom);
*/
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 | #include <cstdio> #define MAX_SIZE 3000000 char palindrom[MAX_SIZE]; int counter = 0; // A function to check if a string str is palindrome void isPalindrome() { // Start from leftmost and rightmost corners of str int l = 0; int h = counter - 1; // Keep comparing characters while they are same while (h > l) { if (palindrom[l++] != palindrom[h--]) { printf("NIE"); return; } } printf("TAK"); } int main() { char ch; int placeHolder; scanf("%d", &placeHolder); getchar(); while ((ch = getchar()) != '\n') { palindrom[counter] = ch; ++counter; } isPalindrome(); /* To nie działa bo myslalem ze da sie zapisac litery a-z (26 znaków) na 4 bitach lecz jednak potrzebne jest 5 bitów int ch; int maska = 0b1111; while ((ch = getchar()) != '\n') { ch = ch - 'a'; //ch = ch & maska; if (counter % 2 == 1) ch <<= 3; palindrom[counter / 2] = palindrom[counter / 2] | ch; ++counter; } for (int i = 0; i < counter; i++) { ch = palindrom[i / 2]; if (i % 2 == 1) { ch = ch >> 4; } else { ch = ch & maska; } ch += 'a'; printf("%c", ch); } */ /* int l = 0; int h = counter - 1; // Keep comparing characters while they are same while (h > l) { if (palindrom[l++] != palindrom[h--]) { printf("%s is Not Palindrome", palindrom); return 0; } } printf("%s is palindrome", palindrom); */ return 0; } |
English