//输入 100001 Zhangsan 1000 30000 50000 0.047 5000 Y 3000
1 1 1500
1 2 500
1 3 500
1 1 7000
2 3 500
0 0 0
无法输出正确答案我仔细没检查出错误 麻烦大家帮我看看
#include
#include
#include
using namespace std;
class Account
{
protected:
long ID;
string name;
public:
Account(){cin>>ID>>name;}
};
class AliPay:virtual protected Account//支付宝
{
protected:
double amount;
int out_limit;
public:
AliPay(){cin>>amount>>out_limit;}
void add1(double& pay)//转入支付宝
{
amount=amount+pay;
}
void sub1(double& pay)//转出支付宝(最高金额)
{
if(pay>amount)
pay=amount;
if(pay>out_limit)
pay=out_limit;
amount-=pay;
}
};
class AliFund:virtual protected Account
{
protected:
double amount;
double rate;
int in_limit;
public:
AliFund(){cin>>amount>>rate>>in_limit;}
void sub2(double& pay)//转出余额宝
{ if(pay>amount)
pay=amount;
amount=amount-pay;
}
void add2(double& pay)//转入余额宝最低金额
{
if(pay>=in_limit)
amount=amount+pay;
}
};
class My_Ali:public AliPay,public AliFund
{
public:
bool auto_collect_flag;
int threshold;
My_Ali()
{
char a;
cin>>a;
if(a=='Y')
{cin>>threshold;
auto_collect_flag=1;
}
else
{
auto_collect_flag=0;
}
} //是否存在资金自动收集阈值
void fundtopay(double& pay)//将余额宝转入支付宝
{
sub2(pay);//转出余额宝
add1(pay);//转入支付宝
autodo(); //将超出支付宝最大金额的钱自动转入余额宝
}
void paytofund(double& pay)
{
sub1(pay);
if(pay>=in_limit)//判断转入余额宝的金额是否大于最低金额
add2(pay);//成功转入
else
add1(pay);//失败
}//支付宝与余额宝之间的转账
void autodo()
{
double t=AliPay::amount-threshold;
if(auto_collect_flag)
{
if(AliPay::amount>threshold)
paytofund(t);
}
}
void out()
{
cout<<"Account for "<"Total: "<"AliPay: "<"AliFund: "<" with rate "<<setiosflags(ios::fixed)<<setprecision(1)<100<<"%"<//1.判断操作的账户类型(1-支付宝,2-余额宝);
//2.具体操作(1转入或2转出 3) ;
//3.输入操作金额;
//4.判断操作后支付宝账户金额是否大于资金自动收集阈值,并计算超出金额sum=total-threshold;
// 5.再判断 in_limit
int main()
{ My_Ali t;
int a,b;
double money;
cin>>a>>b>>money;
while(a!=0&&b!=0&&money!=0)
{
if(a==1)
{
if(b=1)
{
t.add1(money);
t.autodo();// 将超出金额转入余额宝;
}
if(b=2)
t.sub1(money);
if(b=3)
t.paytofund(money);
}
if(a==2)
{
if(b=1)
t.add2(money);
if(b=2)
t.sub2(money);
if(b=3)
t.fundtopay(money);
}
cin>>a>>b>>money;
}
t.out();
return 0;
}
您好!这段代码存在一些问题,主要是在判断条件时使用了赋值运算符而不是相等运算符,导致逻辑错误。下面是修改后的代码:
int main()
{
My_Ali t;
int a,b;
double money;
cin>>a>>b>>money;
while(a!=0&&b!=0&&money!=0)
{
if(a==1)
{
if(b==1)
{
t.add1(money);
t.autodo();// 将超出金额转入余额宝;
}
if(b==2)
t.sub1(money);
if(b==3)
t.paytofund(money);
}
if(a==2)
{
if(b==1)
t.add2(money);
if(b==2)
t.sub2(money);
if(b==3)
t.fundtopay(money);
}
cin>>a>>b>>money;
}
t.out();
return 0;
}
```c++
```
不知道你这个问题是否已经解决, 如果还没有解决的话:这道题目重点在于存储数据和如何遍历数据找到并输出树的叶子。
我一开始是想用指针建一棵树,后来发现太麻烦。麻烦也就算了,还不知道建好的树如何层序遍历。于是把指针树都删掉了,直接存到数组里面。
另外,在网上查了一下如何层序遍历一棵树,找到了递归的思路——写递归函数的时候记录一下相应的层就OK,其实还是先序遍历,只不过通过先序遍历把每一层的元素存到了一个vector数组里面,然后再根据层数,从vector【0】开始遍历每一个vector里面所有的元素,这样下来,就相当于一个层序从左往右的遍历啦!
其实也不一定用vector,所有能充当二元数组的数据结构都可以,只不过一般的数组需要下标访问,而我们不知道每一层具体有几个元素,所以queue数组也是可以哒~
另外,对于树根的查找,其实就是在创建这个数组树的时候,记录一下哪个节点没有出现在其他节点的左右孩子上,你会发现,就一个这样的点,即孤儿——祖宗,也就是树根。
而对于格式问题,我一开始是大大咧咧地cout了“叶子 空格”的,发现都是格式错误。这个题格式要求前后都没有空格的,所以输出的时候要加一个判断,将空格放在树叶前面,而第一个树叶前面不加空格。
AC代码如下:
#include<iostream>
#include<vector>
using namespace std;
struct node {
char left, right;
} ;
node treenode[11];
vector <int> leaf[11];
void cengxubianli(int root, int level) {
if (treenode[root].left == '-' && treenode[root].right == '-') {
leaf[level].push_back(root);
return;
}
if (treenode[root].left != '-') cengxubianli(treenode[root].left - '0', level + 1);
if (treenode[root].right != '-') cengxubianli(treenode[root].right - '0', level + 1);
}
int main() {
int n, findroot[11], reallyroot = 0;
for(int i=0;i<11;i++)
findroot[i]=0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> treenode[i].left >> treenode[i].right;
findroot[treenode[i].left - '0'] = findroot[treenode[i].right - '0'] = 1;
}
for (int i = 0; i < n; i++)
if (findroot[i]==0) {
reallyroot = i;
break;
}
cengxubianli(reallyroot, 1);
bool first=false;
for (int i = 1; i <= 10; i++) {
for (int j = 0; j < leaf[i].size(); j++) {
if(first)cout<<" ";
else first=true;
cout << leaf[i][j];
}
}
system("pause");
return 0;
}
支付宝和余额宝是目前我国使用最广泛的支付和理财工具之一,使用方便且功能强大。以下是一些关于支付宝和余额宝的使用指南和注意事项:
以上就是关于使用支付宝和余额宝的一些指南和注意事项,如有其他疑问,可以在支付宝APP中查找相关说明或咨询客服。