AcWing 3610. 找位置
原题链接
简单
#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;
char ch;
unordered_map<char, vector<int>>mp;
string st;
void solve() {
while (cin >> ch) {
if (mp.find(ch) == mp.end()) {
st.push_back(ch);
}
mp[ch].push_back(m++);
}
for (char&ch : st) {
flag = false;
int siz = mp[ch].size();
if (siz < 2)continue;
for (int i = 0; i < siz; i++) {
cout << ch << ":" << mp[ch][i];
if (i != siz - 1)cout << ",";
}
cout << "\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}