/* 思路: 利用array<int, 26>数组 1. 遍历字符串, 统计每个字符出现的次数 2. 找出出现次数最少的字符出现的次数 3. 去掉出现次数最少的字符 */ #include <array> #include <iostream> using namespace std; int main() { string str; string ans; int min = 20; cin >> str; int len = str.length(); array<int, 26> a { 0 }; for(int i = 0; i < len; i++){ a[str[i] - 'a']++; // 此时每个字符出现的次数已经记在数组中了 } for(int i = 0; i < 26; i++){ if( (a[i] > 0) && (a[i] < min) ){ min = a[i]; // 这是就找到了字符串中出现次数最少的字符的次数 } } // 得到不包含字符串中出现次数最少的字符的字符串 for(int i = 0; i < len; i++){ if(a[str[i] - 'a'] == min){ continue; } ans += str[i]; } cout << ans << endl; return 0; } // 64 位输出请用 printf("%lld")