pta7-25买u盘误差修正
时间: 2023-08-14 18:12:18 浏览: 183
PTA 7-29 删除字符串中的子串
根据提供的引用内容,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 ]
阅读全文