输入一串字符,可以是字母,数字与符号,空格也包含在内,以问号结束(结束标志可以自行设定),实现将字符串中的字母,数字和其他
字符分开,并输出字母串的去重后的结果,最后一行为数字串的回文判断,是为1,不是回文为0.
以下是源代码,在VS2013中测试可用:
#include<string>
using namespace std;
class list
{
char Data;
public:
void Input_Data(char s)
{
Data = s;
}
char Output_Data()
{
return Data;
}
list *next;
list *prior;
};
{
list *p;
p = List;
if (List == NULL)
{
List = s;
return;
}
while (p)
{
if (p->next == NULL)
{
p->next = s;
s->prior = p;
return;
}
p = p->next;
}
cout << “Wrong !” << endl;
}
{
list *p;
list *q;
p = List;
while (p)
{
q = p->next;
while (q)
{
if (q->Output_Data() == p->Output_Data())
{
list *k;
k = q;
q = q->prior;
if (k->next == NULL)
{
k->prior->next = NULL;
}
else
{
k->prior->next = k->next;
k->next->prior = k->prior;
}
delete k;
k = NULL;
}
q = q->next;
}
p = p->next;
}
}
{
list *p;
p = List_A;
while (p)
{
if ((p->Output_Data() >= 65 && p->Output_Data() <= 90) || (p->Output_Data() >= 97 && p->Output_Data() <= 122))
{
list *q = NULL;
q = p;
if (q == List_A)
{
List_A = q->next;
p = q->next;
q->next->prior = NULL;
q->next = NULL;
q->prior = NULL;
}
else if (q->next == NULL)
{
q->prior->next = NULL;
p = q->prior;
q->next = NULL;
q->prior = NULL;
}
else
{
q->prior->next = q->next;
q->next->prior = q->prior;
p = q->prior;
q->next = NULL;
q->prior = NULL;
}
build(List_B,q);
if (p == List_A)
continue;
}
else if (p->Output_Data() >= 48 && p->Output_Data() <= 57)
{
}
else
{
list *q = NULL;
q = p;
if (q == List_A)
{
List_A = q->next;
p = q->next;
q->next->prior = NULL;
q->next = NULL;
q->prior = NULL;
}
else if (q->next == NULL)
{
q->prior->next = NULL;
p = q->prior;
q->next = NULL;
q->prior = NULL;
}
else
{
q->prior->next = q->next;
q->next->prior = q->prior;
p = q->prior;
q->next = NULL;
q->prior = NULL;
}
build(List_C, q);
if (p == List_A)
continue;
}
p = p->next;
}
return;
}
{
list *p;
p = List;
list *q;
while (p->next != NULL)
{
p = p->next;
}
q = p;
p = List;
while (p && q)
{
if ( p->Output_Data() != q->Output_Data() )
{
return 0;
}
p = p->next;
q = q->prior;
}
return 1;
}
{
list *List_A = NULL;
char input;
while (cin.get(input))
{
if (input == ‘?’)
{
break;
}
list *s;
s = new list();
s->next = NULL;
s->prior = NULL;
s->Input_Data(input);
build(List_A,s);
}
list *List_B = NULL;
list *List_C = NULL;
classify(List_A,List_B,List_C);
list *p;
p = List_A;
if (List_A == NULL)
{
cout << “-1”;
}
else
while (p)
{
cout << p->Output_Data();
p = p->next;
}
cout << endl;
p = List_B;
if (List_B == NULL)
{
cout << “-1”;
}
else
while (p)
{
cout << p->Output_Data();
p = p->next;
}
cout << endl;
if (List_C == NULL)
{
cout << “-1”;
}
else
while (p)
{
cout << p->Output_Data();
p = p->next;
}
cout << endl;
check(List_B);
p = List_B;
if (List_B == NULL)
{
cout << “-1”;
}
else
while (p)
{
cout << p->Output_Data();
p = p->next;
}
cout << endl;
if (List_A != NULL)
{
cout << Check_repeat(List_A) << endl;
}
else cout << “-1” << endl;
}