无敌
2025-07-29 17:00:31
发布于:上海
4阅读
0回复
0点赞
#include<iostream>//输入输出流
#include<algorithm>//函数
#include<cmath>//数学
#include<stack>//栈
using namespace std;//标准命名空间
struct number{//结构体类型number
int x;
int index;//包含int类型的x和index(值和下标)
};
stack<int> s;
int add(number a,number b){ //自定义函数number类型的add,参数为number 类型的a和b
return a.x+b.x;
}
int main(){//主函数
//首先我们要学过自定义函数
//其次我们要学过结构体
//而且我们要学过栈
//最后我们要学会结构体输入与输出
number a,b;//声明两个number型变量a,b存储待加数据
cin>>a.x>>b.x;//输入a,b的值
a.index=1;
b.index=2;//给a,b写入下标index
number r,t;
s.push(a.x);
s.push(b.x);
r.x=s.top();
s.pop();
t.x=s.top();
cout<<add(r,t);
}
点个赞吧
是不是发现index没用,50赞发2.0会用到
代码亲测能过
这里空空如也
有帮助,赞一个