原题:3610. 找位置
对给定的一个字符串,找出有重复的字符,并给出其位置
#include <iostream>
#include <map>
#include <vector>
using namespace std;
map<char, vector<int>> a;
map<char, int> b;
int main() {
string s;
cin >> s;
int len = s.length();
for (int i =0; i < len; i++) {
a[s[i]].push_back(i);
}
bool first = true;
for (int i =0; i < len; i++) {
int size = a[s[i]].size();
if (size > 1 && !b[s[i]]) {
first = true;
for (int j = 0; j < size; j++) {
if (first == false) {
cout << ',';
}
cout << s[i] << ':' << a[s[i]][j];
first = false;
}
b[s[i]] = 1;
cout << endl;
}
}
return 0;
}