AcWing 718. STL模板——map 写法代码
原题链接
简单
作者:
150432
,
2024-12-09 20:05:06
,
所有人可见
,
阅读 3
一道循环题目发现好像没有人用map, 特水一篇题解
C++ 代码
#include <bits/stdc++.h>
using namespace std;
int n, x, ans;
char c;
map<char, int> m;
int main()
{
scanf("%d", &n);
while(n --)
{
scanf("%d %c", &x, &c);
ans += x;
m[c] += x;
}
printf("Total: %d animals\nTotal coneys: %d\nTotal rats: %d\nTotal frogs: %d\n", ans, m['C'], m['R'], m['F']);
printf("Percentage of coneys: %.2lf %%\nPercentage of rats: %.2lf %%\nPercentage of frogs: %.2lf %%\n", 100.0 * m['C'] / ans, 100.0 * m['R'] / ans, 100.0 * m['F'] / ans);
}