题解 | #找位置#
找位置
https://www.nowcoder.com/practice/e3b2cc44aa9b4851bdca89dd79c53150
#include <iostream>
#include <string>
#include <vector>
using namespace std;
const int N = 101;
string str;
vector<int> pos[N];
int main() {
while (cin >> str) {
for(int i = 0; i < str.size(); i ++){
pos[str[i]].push_back(i);
}
for(int i = 0; i < str.size(); i ++){
if(pos[str[i]].size() > 1){
for(int j = 0; j < pos[str[i]].size(); j ++){
if(j == 0) cout << str[i] << ":" << pos[str[i]][j];
else cout << "," <<str[i] << ":" << pos[str[i]][j];
}
pos[str[i]].clear();
cout << endl;
}
}
}
return 0;
}
// 64 位输出请用 printf("%lld")
查看4道真题和解析