题解 | #找位置#

找位置

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")

全部评论

相关推荐

09-14 17:23
门头沟学院
故事和酒66:所以说副业很重要,程序员干到40岁,再怎么也赚300万了,吃吃利息也够活下去
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务