2 条题解
-
-1
李圣凡@吴江区实验初级中学 (lsf123456lsf) LV 8 @ 4 年前
#include<iostream>
using namespace std;struct Node
{
int xi_shu;
int zhi_shu;
//int x_x;
Node *next;
};/*
class Array
{
protected:public:
};
*/class LinkList//:public Array
{
private:
//数组的私有成员
int *a;
int n;
int size;//链表的私有成员
Node *head;public:
/*
LinkList(int set_n)
{
n=set_n*2;
size=n*2;
a=new int[size];
}
/
/
virtual ~Array()
{
delete []a;
}
*/void set_array()
{
for(int i=0;i<n;i++)
{
cin>>a[i];
}
}/*
void output()
{
for(int i=0;i<n;i++)
cout<<a[i];
cout<<endl;
}
*/void push(int x,int y)
{
Node *newp=new Node;
newp->xi_shu=x;
newp->zhi_shu=y;
newp->next=head;
head=newp;
}LinkList(int set_n)
{
n=set_n*2;
size=n*2;
a=new int[size];
for(int i=0;i<n;i++)
{
cin>>a[i];
}head=NULL;
for(int i=n-2;i>=0;i=i-2)
push(a[i],a[i+1]);
}void output()
{
Node *p=head;
while(p!=0)
{
cout<<p->xi_shu<<"x^"<<p->zhi_shu<<" ";
p=p->next;
}
cout<<endl;
}int do_the_math(int x)
{
int mult=0;
int sum=0;
int tmp=0;
Node *p=head;
while(p!=0)
{
tmp=1;
for(int i=1;i<=p->zhi_shu;i++)
{
tmp=tmp*x;
}
mult=tmp*p->xi_shu;
sum=sum+mult;
p=p->next;
}
return sum;
}};
int main()
{
int n;
int x;
cin>>n;
LinkList a(n);//把set_array()集成到构造函数里了,虽然有一点不习惯,但按照构造就赋值的作用看,这种写法是优于用set_array()函数的(主要是用set_array函数有一部分指针问题无法解决)cin>>x;
cout<<a.do_the_math(x)<<endl;system("pause");
return 0;
} -
-15 年前@
- 1
信息
- ID
- 1036
- 难度
- 1
- 分类
- (无)
- 标签
- 递交数
- 245
- 已通过
- 152
- 通过率
- 62%
- 被复制
- 1
- 上传者