#include <iostream>
#include"string"
using namespace std;
const int maxnum=5;
class goodslist{
public:
int num;
int type;
};
goodslist List[maxnum];//购物单
int Listnum=0;// 购物车里面数量
int price[3]={10,120,30};//价格
int money=0;
int score=0;
int costscore=0;
void init()// 初始化
{
money=3000;
score=150;
cout<<"S001"<<endl;
}
void choice(char type,char goodnum[])// 订单的加入
{
if(Listnum==5)
{cout<<"E003"<<endl; return; }
int numin=atoi(goodnum);
if((type-'0')>2||(type-'0')<0||numin<=0||numin>100)
{cout<<"E002"<<endl; return; }
List[Listnum].num=numin;
List[Listnum].type=type-'0';
cout<<"S002"<<endl;
Listnum++;
}
void cancel(char type,char goodnum[])// 订单的取消
{
if(Listnum==0)//订单为空
{cout<<"E005"<<endl; return; }
int numin=atoi(goodnum);
if((type-'0')>2||(type-'0')<0||numin<=0||numin>100)//不在范围内
{cout<<"E002"<<endl; return; }
//订单的查询删除 这里设置有一个变量判断
for(int i=0;i<Listnum;i++)
{
//如果能够匹配订单
if(List[i].num==numin&&List[i].type==(type-'0'))
{//删除的实现 只有移动了;
for(;i<Listnum-1;i++)//
{
List[i].num=List[i+1].num;
List[i].type=List[i+1].type;
}
Listnum--;
cout<<"S003"<<endl;
return;
}
}
// 订单不存在 上面执行完了还没有
cout<<"E004"<<endl; return;
}
void check(char temp)// 命令查询
{
int check=temp-'0';
if(check>1||check<0)
{cout<<"E002"<<endl; return ;}
if(check==0)//查询购物卡 余额 积分
{cout<<money<<endl<<score<<endl;return;}
if(check==1)//订单数量以及商品没中的总数
{
cout<<Listnum<<endl;
int food=0,cloth=0,book=0;
for(int i=0;i<Listnum;i++)
{
if(List[i].type==0)
food=food+List[i].num;
if(List[i].type==1)
cloth=cloth+List[i].num;
if(List[i].type==2)
book=book+List[i].num;
}
cout<<food<<endl<<cloth<<endl<<book<<endl;
}
}
//结算 购物
void buygoods()
{ //购物车为空
if(Listnum==0)
{cout<<"E005"<<endl;return;}
//结算计算出优惠方案
int sumevery[3]={0};
for(int i=0;i<Listnum;i++)
{
sumevery[List[i].type]+=List[i].num*price[List[i].type];//求和 因为type和价格对应
}
int billever[3][3]={0};
for(int i=0;i<3;i++)
billever[i][0]=sumevery[i];
billever[0][1]=(int)(billever[0][0]*0.9);
billever[0][2]=billever[0][0]-billever[0][0]/100*18;
billever[1][1]=billever[1][0]-billever[1][0]/200*40;
billever[2][1]=(int)(billever[2][0]*0.5);
//判断总体方案是否优惠
int paymoney=0x7fffffff;//需要支付的钱
int count=0,jifenshiyong=0;
for(int i=0;i<3;i++)
for(int j=0;j<2;j++)
for(int k=0;k<2;k++)
{ count=billever[0][i]+billever[1][j]+billever[2][k];
if(count>=500)
{
//付款这个怎么比较哪个更好呢? 就是付钱出去最少??? 不考虑以后积分
if(score>=120)//积分120
{
if(count*0.8>count-120)
{
count-=120;
jifenshiyong=120;
}
else
{
count=count*0.8;
}
}
else//积分没有120
{
if(count*0.8>count-score)
{
count-=score;
jifenshiyong=score;
}
else
{
count=count*0.8;
}
}
}
if(count<paymoney)
{paymoney=count;
costscore=jifenshiyong;
}
}//三个for循环的括号
//以上处理完了最后的结账的总数
if(money<paymoney)
{cout<<"E006"<<endl;return;}
else
{//输出消费金额 消费积分 新增积分
cout<<paymoney<<endl<<costscore<<endl<<paymoney/10<<endl;
money-=paymoney;
score=score-costscore+(paymoney/10);
//成功了清空购物车
Listnum=0;
for(int i=0;i<5;i++)
{
List[i].num=0;
List[i].type=0;
}
}
}
int main()
{
char input[10]="";
//下面进行输入判断;
while(gets(input))
{// 输入后就判断命令问题
//因为命令合法性都不需要考虑 所以对于正确性的检测不必
char goodnum[4]="";
switch (input[0])
{
case 'r':
init();
break;
case 'o':// 订单加入
goodnum[0]=input[4],goodnum[1]=input[5],goodnum[2]=input[6];
choice(input[2],goodnum);
break;
case 'c'://订单取消
goodnum[0]=input[4],goodnum[1]=input[5],goodnum[2]=input[6];
cancel(input[2],goodnum);
break;
case 'b'://买
buygoods();
break;
case 'l'://查询
check(input[2]);
break;
case 'e':// 结束
return 0;
default:
break;
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
华为OJ题目集合 (158个子文件)
医院门诊管理系统.cpp 18KB
Decrease.cpp 5KB
FindSimilarWord.cpp 5KB
sqlist.cpp 4KB
ObjMgt.cpp 4KB
sqlist.cpp 4KB
Polynomial.cpp 3KB
sqlist.cpp 3KB
SwiSchedule.cpp 3KB
SwiSchedule.cpp 3KB
OJ.cpp 3KB
sqlist.cpp 3KB
OJ.cpp 2KB
encrypt.cpp 2KB
OJ.cpp 2KB
ConvertMsg.cpp 2KB
find_string.cpp 2KB
OJ.cpp 2KB
OJ.cpp 2KB
PhoneBookProcess.cpp 2KB
OJ.cpp 2KB
OJ.cpp 2KB
CalculateAbsoluteDays.cpp 2KB
OJ.cpp 2KB
OJ.cpp 2KB
IPAddressValid.cpp 2KB
OJ.cpp 2KB
OJ.cpp 2KB
OJ.cpp 2KB
OJ.cpp 2KB
OJ.cpp 2KB
OJ.cpp 1KB
sqlist.cpp 1KB
OJ.cpp 1KB
OJ.cpp 1KB
OJ.cpp 1KB
Degressive.cpp 1KB
OJ.cpp 1KB
OJ.cpp 1KB
OJ.cpp 1KB
OJ.cpp 1KB
OJ.cpp 1KB
OJ.cpp 1KB
OJ.cpp 1KB
OJ.cpp 940B
OJ.cpp 940B
OJ.cpp 902B
OJ.cpp 884B
OJ.cpp 839B
OJ.cpp 758B
OJ.cpp 723B
OJ.cpp 723B
RotundityArea.cpp 720B
OJ.cpp 680B
OJ.cpp 660B
bracketmatching.cpp 651B
OJ.cpp 648B
OJ.cpp 634B
OJ.cpp 619B
OJ.cpp 615B
OJ.cpp 596B
OJ.cpp 584B
OJ.cpp 565B
OJ.cpp 555B
OJ.cpp 513B
OJ.cpp 496B
OJ.cpp 472B
OJ.cpp 467B
OJ.cpp 453B
OJ.cpp 419B
OJ.cpp 389B
OJ.cpp 268B
OJ.cpp 263B
OJ.cpp 244B
OJ.h 968B
OJ.h 761B
OJ.h 654B
OJ.h 592B
PhoneBookProcess.h 480B
OJ.h 414B
OJ.h 339B
OJ.h 308B
ObjMgt.h 306B
OJ.h 273B
OJ.h 262B
sqlist.h 252B
sqlist.h 252B
OJ.h 247B
find_string.h 223B
OJ.h 216B
OJ.h 207B
OJ.h 179B
OJ.h 176B
OJ.h 176B
OJ.h 175B
OJ.h 171B
OJ.h 170B
OJ.h 169B
OJ.h 166B
OJ.h 160B
共 158 条
- 1
- 2
资源评论
- 一梦华胥引2016-03-29非常好的资源,感谢分享。
- 嗨皮0092016-08-21感谢分享,很好的参考
- Penny蕾儿2016-10-15只有答案 想要原题
- chinawqf2017-10-08资源还可以。
如影随形123
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功