锘??xml version="1.0" encoding="utf-8" standalone="yes"?>#include <iostream>
#include <string.h>
using namespace std;
bool is_equal(char str[])
{
int len=strlen(str);
if (len==0)
return false;
else if (len%2==0)
{
int mid=len/2;
bool flag=true;
int i,j;
for(i=0, j=len-1; i<mid; i++,j--)
{
if (str[i]==str[j])
continue;
else
{
flag=false;
break;
}
}
return flag;
}
else
return false;
}
int main()
{
char str[]="helleh";
int return_val;
if (is_equal(str))
return_val=1;
else
return_val=0;
cout<<return_val<<endl;
}
]]>//鏈夊簭澶氶」寮忓姞娉?/span>
#include <iostream>
using namespace std;
struct Node
{
int coef;
int exp;
Node *next;
};
class MExpression
{
private :
Node *first;
public :
MExpression();
void InsertNode(int coef,int exp);
void DeleteNode(int exp);
void Add(MExpression me);
void PrintAll();
};
MExpression::MExpression()
{
first->next=NULL;
}
void MExpression::InsertNode(int coef,int exp)
{
Node *s=new Node();
Node *p=first;
while(p->next!=NULL)
p=p->next;
s->coef=coef;
s->exp=exp;
s->next=p->next;
p->next=s;
}
void MExpression::DeleteNode(int exp)
{
Node *p=first->next;
Node *q;
q=first;
while(p!=NULL)
{
if (p->exp==exp) break;
q=p;
p=p->next;
}
q->next=p->next;
delete p;
}
void MExpression::Add(MExpression me)
{
int i=0,j=0;
Node *p=first->next;
Node *q=me.first->next;
Node *pp,*qq;
pp=first;
qq=me.first;
while(p&&q)
{
if (p->exp>q->exp)
{
InsertNode(q->coef,q->exp);
q=q->next;
}
else if(p->exp==q->exp)
{
p->coef+=q->coef;
p=p->next;
q=q->next;
}
else
{
p=p->next;
}
}
while(q)
{
InsertNode(q->coef,q->exp);
q=q->next;
}
}
void MExpression::PrintAll()
{
cout<<"=== coef c exp e ==="<<endl;
Node *p=first->next;
while(p!=NULL)
{
cout<<p->coef<<" c "<<p->exp<<" e ";
p=p->next;
}
}
int main()
{
MExpression *me1=new MExpression();
MExpression *me2=new MExpression();
me1->InsertNode(1,1);
me1->InsertNode(2,2);
me1->InsertNode(3,3);
me1->InsertNode(4,4);
me2->InsertNode(1,2);
me2->InsertNode(2,3);
me2->InsertNode(3,4);
me2->InsertNode(4,5);
me1->Add(*me2);
me1->PrintAll();
}
]]>/**//*
寰幆鍙岄摼琛?br>
*/
#include <iostream>
using namespace std;
struct Node
{
int data;
Node *next;
Node *prior;
};
class CycleDLList
{
private :
Node *first;
public:
CycleDLList();
void InsertNode(int data);
void DeleteNode(int data);
void PrintAll();
};
CycleDLList::CycleDLList()
{
first->prior=first;
first->next=first;
}
void CycleDLList::InsertNode(int data)
{
Node *s=new Node();
s->data=data;
Node *p=first->next;
while(p->next!=first)
{
p=p->next;
}
s->prior=p;
s->next=p->next;
p->next->prior=s;
p->next=s;
}
void CycleDLList::DeleteNode(int data)
{
Node *p=first->next;
Node *q;
while(p!=first)
{
if(p->data==data) break;
q=p;
p=p->next;
}
if (p!=first)
{
q->next=p->next;
p->next->prior=q;
delete p;
}
}
void CycleDLList:: PrintAll()
{
Node *p=first->next;
Node *q=first->prior;
cout<<"p=p->next"<<endl;
while(p!=first)
{
cout<<p->data<<" ";
p=p->next;
}
cout<<endl;
cout<<"q=q->prior"<<endl;
while(q!=first)
{
cout<<q->data<<" ";
q=q->prior;
}
}
int main()
{
CycleDLList *cd=new CycleDLList();
cd->InsertNode(5);
cd->InsertNode(4);
cd->InsertNode(3);
cd->InsertNode(2);
cd->PrintAll();
cd->DeleteNode(2);
cd->PrintAll();
}
]]>#include <iostream>
2using namespace std;
3
4struct Node
5
{
6 int data;
7 Node *next;
8 };
9 class CycleLinkList
10
{
11 private :
12 Node *first;
13 public :
14 CycleLinkList();
15 void InsertNode(int data);
16 void DeleteNode(int data);
17 void PrintAll();
18 };
19
20 CycleLinkList:: CycleLinkList()
21
{
22 first=first->next;
23 }
24 void CycleLinkList::InsertNode(int data)
25
{
26 Node *s=new Node();
27 s->data=data;
28 Node *p=first;
29 if (p->next==first)
30
{
31 s->next=first->next;
32 first->next=s;
33 }
34 else
35
{
36 while(p->next!=first) p=p->next;
37 s->next=p->next;
38 p->next=s;
39 }
40 }
41
42 void CycleLinkList::DeleteNode(int data)
43
{
44 Node *p=first->next;
45 Node *q=first->next;
46 while(p!=first)
47
{
48 if (p->data==data) break;
49 else
50
{
51 q=p;
52 p=p->next;
53 }
54 }
55 q->next=p->next;
56 delete p;
57 }
58 void CycleLinkList:: PrintAll()
59
{
60 Node *p=first->next;
61
62 while(p!=first)
63
{
64 cout<<p->data<<" ";
65 p=p->next;
66 }
67 }
68 int main()
69
{
70 CycleLinkList *cl=new CycleLinkList();
71 cl->InsertNode(3);
72 cl->InsertNode(4);
73 cl->InsertNode(5);
74 cl->InsertNode(6);
75 cl->PrintAll();
76 cl->DeleteNode(4);
77 cl->PrintAll();
78 }
]]>
姣忛」鐨勫垎瀛愬垎姣嶆槸鐢辨枑娉㈤偅濂戞暟鍒椾腑鍙栫浉閭?cè)潥勪袱涓緱鍒板Q岃綆楃粨鏋滀繚鐣欎笁浣嶅皬鏁?/font>
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
int n;
double t;
while(cin>>n){
double a=1;
double b=1;
double sum=0;
for(int i=1;i<=n;i++){
sum+=a/b;
t=a;
a+=b;
b=t;
}cout<<setiosflags(ios::fixed)<<setprecision(3);
cout<<sum<<endl;
}
return 0;
}
]]>#include <iostream>
#include <string>
using namespace std;
const int Max=100;
char *sreverse(char *s,int a,int b)
{
char e;
char c;
if(b>a)
{
c=s[a];
e=s[b];
s[a]=e;
s[b]=c;
a++;
b--;
sreverse(s,a,b);
}
return s;
}
int main()
{ int i;
char *a=new char[Max];
char *p;
cin>>a;
cin>>i;
if(i==0) cout<<a<<endl;
else if(i<0){
i=-i;
sreverse(a,0,i-1);
sreverse(a,i,strlen(a)-1);
p=sreverse(a,0,strlen(a)-1);
cout <<p<<endl;
}
else { sreverse(a,strlen(a)-i,strlen(a)-1);
sreverse(a,0,strlen(a)-i-1);
p=sreverse(a,0,strlen(a)-1);
cout <<p<<endl;
}
return 0;
}
鑳戒笉鑳借繘琛屼紭鍖栧晩錛岃秴鏃訛紒錛侊紒
]]>#include <iostream>
using namespace std;
int Rev(int n){
char ch;
if(n>10000) ch='a';
else if(n>1000) ch='b';
else if(n>100) ch='c';
else if(n>10) ch='d';
else if(n>0) ch='e';
else return 1;
switch(ch){
case 'a':if((n/10000)==(n%10)&&((n%10000)/1000)==((n%100)/10)) return 1;
else return 0;
break;
case 'b':if((n/1000)==(n%10)&&((n%1000)/100)==((n%100)/10)) return 1;
else return 0;break;
case 'c': if((n/100)==(n%10)) return 1;
else return 0;break;
case 'd': if((n/10)==(n%10)) return 1;
else return 0;break;
case 'e': return 0;
} return 0;
}
int main()
{ cout<<Rev(654);
cout<<Rev(12321);
cout<<Rev(322);
return 0;
}
]]>#include <iostream>
using namespace std;
struct Node{
int data;
Node *next;
};
class Linkqueue{
public:
Linkqueue();
~Linkqueue();
void Enqueue(int x);
int Dequeue();
int Getqueue();
private:
Node *front;
Node *rear;
};
Linkqueue::Linkqueue(){
Node *s;
s=new Node;
s->next=NULL;
front = rear=s;
}
Linkqueue::~Linkqueue(){
Node *p;
p=new Node;
while(front!=rear){
p=front->next;
p->next=front->next;
delete front;
front=p;
}
}
void Linkqueue::Enqueue(int x){
Node *s;
s=new Node;
s->data=x;
s->next=NULL;
rear->next=s;
rear=s;
}
int Linkqueue::Dequeue(){
if(front==rear) throw "error";
Node *p;
p=new Node;
p=front->next;
int x=p->data;
front->next= p->next;
if(p->next=NULL) rear=front;
delete p;
return x;
}
int Linkqueue::Getqueue(){
return front->next->data;
}
void main()
{
Linkqueue q;
q.Enqueue(2);
cout<<q.Getqueue()<<endl;
q.Enqueue(3);
q.Enqueue(4);
cout<<q.Dequeue()<<endl;
cout<<q.Getqueue();
}
]]>#include <iostream>
using namespace std;
const int MAX=100;
class Seqstack{
public:
int Gettop();
void Push(int x);
Seqstack();
private:
int top;
int data[MAX];
};
Seqstack::Seqstack(){
top=-1;
}
void Seqstack::Push(int x){
cout<<"enter a number:"<<endl;
cin>>x;
data[++top]=x;
cout<<top<<endl;
}
int Seqstack::Gettop(){
int x;
x=data[top];
cout<<x;
return 0;
}
void main()
{
Seqstack s;
s.Push(5);
s.Push(4);
s.Gettop();
}
]]>