题解 | #找位置#

找位置

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

#include <stdio.h>
#include <stdlib.h>

int main() {
    char str[100];
    while (scanf("%s", str) != EOF) {
        for(int i=0;i<strlen(str);i++){
            int flag=0;
            for(int j=i+1;j<strlen(str);j++){
                if(str[i]==str[j] && str[i]!='*'){
                    flag++;
                    if(flag==1){
                        printf("%c:%d",str[i],i);
                        printf(",%c:%d",str[i],j);
                    }
                    else{
                        printf(",%c:%d",str[i],j);
                    }
                    str[j]='*';
                }
            }
            if(flag){
                printf("\n");
            }
        }
    }
    return 0;
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-21 17:59
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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