|
|
|
| #include<fstream>
#include<string>
using namespace std;
struct stack{
string inf;
stack *next;};
stack *initstack(){
return NULL;};
void pushstack(stack *&h,string i){
stack*r=new stack;
r->inf=i;
if(h==NULL) r->next=NULL;
else r->next=h;
h=r;}
string popstack(stack *&h){
stack*r=h;
string i=r->inf;
h=r->next;
delete r;
return i;
}
int main(){
stack *h,*h1;
int s=0;string i,l,c;
h=initstack();
h1=initstack();
ifstream in("in.txt");
ofstream out("out.txt");
while(!in.eof())
{
in>>c;
pushstack(h,c);
}
l=popstack(h);
pushstack(h1,l);
while (h!=NULL)
{
i=popstack(h);
if(l!=i)pushstack(h1,i);
else s++;
}
while(h1!=NULL)
{
out<<popstack(h1)<<' ';
}out<<s;
return 0;
} | |
|
|
|
|
|
|
|
для: Мириам
(27.05.2010 в 08:50)
| | вот примерно так на очередь но она с ошибкой
#include<fstream>
#include<string>
using namespace std;
struct queue{
string inf;
queue *next;};
queue *initqueue(){
return NULL;};
void push(queue *&h,queue *&t, string i){
queue*r=new queue;
r->inf=i;
r->next=NULL;
if(h==NULL) h=r;
else t->next=r;
t=r;}
string pop(queue *&h, queue *&t){
queue*r=h;
string i=r->inf;
h=r->next;
if(h==NULL) t=NULL;
delete r;
return i;}
int main(){
queue *h,*h1,*t,*d,*g,*r;
int s=0;
string i,l,c;
h=initqueue();
h1=initqueue();
t=initqueue();d=initqueue();
g=initqueue();r=initqueue();
ifstream in("in.txt");
ofstream out("out.txt");
while(!in.eof())
{
in>>c;
push(h,t,c);
}
l=pop(h,t);
push(h1,t,l);
while (h!=NULL)
{
i=pop(h,t);
if(l!=i) push(r,g,i);
else push(h1,d,i);
s++;
}
while(h1!=NULL)
{
out<<pop(h1,d)<<' ';
}
out<<s;
return 0;
} | |
|
|
|