# ZeroJudge - b847: 一些字串 ### 題目連結:https://zerojudge.tw/ShowProblem?problemid=b847 ###### tags: `ZeroJudge` `字串` ```cpp= #include <iostream> #include <iomanip> #include <cstring> #include <string> #include <cctype> using namespace std; int main() { cin.sync_with_stdio(false); cin.tie(nullptr); int counts[128], total; string input; while (getline(cin, input)) { memset(counts, 0, sizeof(counts)); total = 0; for (int i = 0; i != input.size(); ++i) if (isalpha(input[i])) { ++counts[input[i] | 32]; ++total; } for (int i = 'a'; i <= 'z'; ++i) cout << counts[i] << ' '; cout << '\n'; for (int i = 'a'; i <= 'z'; ++i) cout << fixed << setprecision(2) << 100.0 * counts[i] / total << ' '; cout << '\n'; } } ```