题解 | #找位置#
找位置
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"); } } } }