#include
#include
#include
using namespace std;
class _Item: public pair < int,int >
{
public:
_Item(): pair < int,int > (int(),int()){}
_Item(int a,int b): pair < int,int > (a,b){}
_Item(const _Item &rhs): pair < int,int > (rhs.first,rhs.second){}
inline bool operator < (const _Item &other)const
{
return second < other.second;
}
inline bool operator==(const _Item &other)const
{
return second==other.second;
}
inline bool operator > (const _Item &other)const
{
return second > other.second;
}
inline void operator+=(const _Item &other)
{
first+=other.first;
}
inline void operator*=(const _Item &other)
{
first*=other.first;
second+=other.second;
}
void operator=(const _Item &other)
{
first=other.first;
second=other.second;
}
friend istream &operator>>(istream &is,_Item &it)
{
is>>it.first>>it.second;
return is;
}
friend ostream &operator<<(ostream &os,const _Item &it)
{
if(it.first > 0)
os<<"+";
os<
return os;
}
};
class EqualZero
{
public:
inline bool operator()(const _Item &it)const
{
return it.first==0;
}
};
typedef list < _Item > List;
typedef List::iterator iList;
void InputList(List &la)
{
la.clear(); //移除所有元素,清空容器
iList il;
_Item temp;
cin>>temp;
temp;
while(temp.first!=0||temp.second!=0)
{
if(la.end()!=(il=find(la.begin(),la.end(),temp)))//begin()返回一个双向迭代器,指向第一个元素.end()返回一个双向迭代器,指向最后一个元素之后
{
*il+=temp;
}
else
{
la.push_back(temp);//在temp位置插入元素,并返回新元素位置
}
cin>>temp;
}
la.sort();
}
void ShowList(List &la)
{
if(la.empty())
return ;
iList il=la.begin();
cout<
cout<<"次方";
++il;
while(il!=la.end())
{
cout<< *il;
++il;
}
cout<
一篇发布下了,还有这部分。p.s.:cout不用注释了。
List AddList(List &la,List &lb)
{
if(la.empty())
return lb;
else if(lb.empty())
return la;
List lc(la);
iList ilb,ilc;
for(ilb=lb.begin();ilb!=lb.end();++ilb)
{
ilc=lc.begin();
while(ilc!=lc.end()&& *ilc < *ilb)
++ilc;
if(ilc==lc.end())
lc.push_back(*ilb);//在尾部添加一个*lib的副本
else if(*ilc== *ilb)
*ilc+= *ilb;
else
lc.insert(ilc, *ilb);//在lic位置插入*lib的副本,并返回新元素位置
}
return lc;
}
List MulList(List &la,List &lb)
{
List lc;
iList ilb,ilt;
for(ilb=lb.begin();ilb!=lb.end();++ilb)
{
List temp(la);
for(ilt=temp.begin();ilt!=temp.end();++ilt)
{
*ilt*= *ilb;
}
lc=AddList(lc,temp);
}
return lc;
}