//土尔逊Torson 编写于2023/4/14 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <map> #include <stdlib.h> #include <iostream> #include <string.h> using namespace std; const int numMAX = 101; int main() { map<char, int> findIndex; char arr[numMAX] = { '\0' }; while (scanf("%s", arr) != EOF) { int n = strlen(arr); for (int i = 0; i < n; ++i) { if (findIndex.find(arr[i]) != findIndex.end()) { int val = findIndex[arr[i]]; findIndex[arr[i]] = val + 1; } else { findIndex[arr[i]] = 1; } } //测试和调节BUG //printf("\n"); //printf("%d\n", strlen(arr)); //for (auto it = findIndex.begin(); it != findIndex.end(); ++it) { // cout << it->first << " = " // << it->second << '\n'; //} //for (int i = 0; i < strlen(arr); ++i) { // printf("%c ", arr[i]); //} //printf("\n"); for (int i = 0; i < n; ++i) { if (findIndex[arr[i]] >= 2) { for (int j = 0; j < n; ++j) { if (arr[j] == arr[i]) { if (findIndex[arr[i]] > 1) { printf("%c:%d,", arr[j], j); int val = findIndex[arr[i]]; findIndex[arr[i]] = val - 1; } else if (findIndex[arr[i]] == 1) { printf("%c:%d", arr[j], j); int val = findIndex[arr[i]]; findIndex[arr[i]] = val - 1; } } } printf("\n"); } } } system("pause"); return EXIT_SUCCESS; } // 64 位输出请用 printf("%lld")