1 条题解
-
0
核心逻辑
计算“有标志的店”占“总店数”的百分比,公式为:
百分比 =(有标志的店数 ÷ 总店数)× 100%
需保留小数点后4位(即使末尾为零也需显示)。代码实现
C
#include <stdio.h> int main() { double total, special; scanf("%lf %lf", &total, &special); double percentage = (special / total) * 100; // 计算百分比 printf("%.4f\n", percentage); // 保留4位小数 return 0; }C++
#include <bits/stdc++.h> using namespace std; int main() { double total, special; cin >> total >> special; double percentage = (special / total) * 100; cout << fixed << setprecision(4) << percentage << endl; // 固定4位小数 return 0; }Python
total, special = map(float, input().split()) percentage = (special / total) * 100 print("{0:.4f}".format(percentage)) # 格式化保留4位小数验证(样例输入
100 1)计算过程:( (1 ÷ 100) × 100 = 1.0 ),输出
1.0000,符合样例要求。所有输入均按公式精确计算,并通过格式控制确保保留4位小数。
- 1
信息
- ID
- 442
- 时间
- 1000ms
- 内存
- 64MiB
- 难度
- 7
- 标签
- 递交数
- 152
- 已通过
- 38
- 上传者