Pagini recente » Autentificare | Istoria paginii runda/oni_2012_ziua2_clasele_xi-xii/clasament | Cod sursa (job #2034221) | Cod sursa (job #971214) | Cod sursa (job #2201445)
#include <iostream>
using namespace std;
int n;
char a;
struct node{
char key;
node * next;
};
void adaugare(node * & p , char x)
{
node * q = new node;
q -> key = x;
q -> next = NULL;
if(p == NULL)
{
p = q;
}
else
{
node * t = p;
while(t -> next != NULL)
t = t -> next;
t -> next = q;
}
}
void afisare(node * p)
{
while(p != NULL)
{
cout << p -> key << " ";
p = p -> next;
}
}
bool palindrom(node *l)
{
node * pr = new node;
node * ult = new node;
node * p_ult = new node;
pr = l;
while(pr != NULL)
{
ult = pr;
p_ult = pr;
while(ult -> next != NULL)
{
ult = ult -> next;
if(ult -> next -> next != NULL)
p_ult = ult -> next;
}
if(ult -> key != pr -> key)
return false;
pr = pr -> next;
p_ult -> next = NULL;
}
return true;
}
int main()
{
cin >> n;
node * prim = new node;
prim = NULL;
for(int i = 0; i < n; ++i)
{
cin >> a;
adaugare(prim, a);
}
//afisare(prim);
cout << palindrom(prim);
}