AcWing 3581. 单词识别
原题链接
简单
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 1e6 + 10;
int t, n, m, k, l, r, op, x, y;
int f[N];
bool flag;
map<string, int> mp;
string str;
string tmp;
void solve() {
getline(cin, str);
str.push_back('.');
for (char &ch : str) {
if (isalpha(ch)) {
if (ch >= 'A' && ch <= 'Z') {
ch += 32;
}
tmp.push_back(ch);
} else {
if(!tmp.empty()){
mp[tmp]++;
}
tmp.clear();
}
}
for (auto &[k, v] : mp) {
cout << k << ":" << v << "\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}