题解 | #找位置#

找位置

https://www.nowcoder.com/practice/e3b2cc44aa9b4851bdca89dd79c53150

#include<iostream>
#include<cstring>

using namespace std;

const int N = 200;
int a[N];
int e[N][N];

int main(){
    string str;
    cin >> str;
    memset(e, -1, sizeof e);
    for(int i = 0; i < str.size(); i ++){
        int x = str[i];
        e[x][a[x]] = i;
        a[x] ++;
    }
    for(int i = 0; i < str.size(); i ++){
        if(a[str[i]] > 1 && i == e[str[i]][0]){
            for(int j = 0; j < a[str[i]]; j ++){
                if(e[str[i]][j] != -1) printf("%c:%d", str[i], e[str[i]][j]);
                if(j == a[str[i]] - 1) printf("\n");
                else printf(",");
            }
        }
    }
    return 0;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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