题解 | #找位置#

找位置

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

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define len 1000
#define maxint 1<<31-1



int main(){
    char str[101];

    while(fgets(str,sizeof(str),stdin)){
        int n = strlen(str)-1;
        int tag[len] = {0};
        for(int i = 0;i<n;i++){
            tag[str[i]]++;
        }
        for(int i = 0;i<n;i++){
            if(tag[str[i]]>1){
                tag[str[i]] = 0;
                int flag = 0;
                for(int j = i;j<n;j++){
                    if(str[j]==str[i]){
                        if(flag){
                            printf(",");
                        }
                        flag = 1;
                        printf("%c:%d",str[i],j);
                    }
                }
                printf("\n");
            }
        }
    }
}

全部评论

相关推荐

码农索隆:有点耳熟,你们是我教过最差的一届
点赞 评论 收藏
分享
06-07 19:59
门头沟学院 C++
补药卡我啊😭:都快15年前的了还在11新特性
你的简历改到第几版了
点赞 评论 收藏
分享
07-10 11:08
门头沟学院 Java
投递京东等公司9个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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