PTA 1020 月饼 (25 分)

文章目录

code1 25分

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct yuebing {
   
	double sale;
	double store;
	double price;
};
bool cmp(yuebing a, yuebing b) {
   return a.price > b.price;}
int main()
{
   
	double kind, need,profit=0;
	cin >> kind >> need;
	vector<struct yuebing>v(kind);
	for (int i = 0
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,pta7-25买U盘误差修正的问题可能涉及到处理汉字输出和浮点数的处理。在给出的代码中,使用了二维数组来保存汉字字符,通过索引来输出相应的汉字。对于浮点数的处理,使用了四舍五入的方法来修正误差。具体的代码实现如下: ```cpp #include <bits/stdc++.h> using namespace std; char a1\[10\]\[5\] = {"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"}; char s1\[11\]\[5\] = {"","角","元","拾","佰","仟","万","拾","佰","仟","亿"}; int main() { int t = 0, i; double a, b; char s\[40\]; cin >> a >> b; double c = a * b + 0.00004; printf("单价: %.2f元/克\n", a + 0.00004); printf("重量: %.2f克\n", b + 0.00004); printf("金额: %.2f元\n", c); printf("大写: "); sprintf(s, "%.2lf", c); for (int i = 0; s\[i\]; i++) { if (s\[i\] == '.') break; t++; } for (i = 0; s\[i\]; i++) { if (s\[i\] == '.') break; printf("%s%s", a1\[s\[i\] - '0'\], s1\[t + 1\]); t--; } printf("%s角%s\n", a1\[s\[i + 1\] - '0'\], a1\[s\[i + 2\] - '0'\]); return 0; } ``` 这段代码可以计算出给定单价和重量的金额,并将金额以大写的形式输出。同时,还修正了浮点数的误差。 #### 引用[.reference_title] - *1* *2* [PTA:7-137 出售金项链(误差修正版) (10)](https://blog.csdn.net/weixin_43581819/article/details/104144588)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [PTA 7-25 买U盘(误差修正版)](https://blog.csdn.net/peng_papa/article/details/126748424)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值