Advertisement

华为OD机试真题 C++字符统计与重排 2022 Q4 100分

阅读量:

**■**题目描述

复制代码
 #include <bits/stdc++.h>

    
  
    
 using namespace std;
    
  
    
 class Solution {
    
 public:
    
     string CharacterStatistics(string &s)
    
     {
    
     vector<int>array(256,0);
    
     for (char i : s) {
    
         array[(int)i]++;
    
     }
    
     int maxx = *max_element(array.begin(), array.end());
    
     string StringBuilder;
    
     for (int i = maxx; i > 0; i --) {
    
         for (int j = 97; j < 123; j ++) {
    
             if (array[j] == i) {
    
                 StringBuilder.push_back((char)j);
    
                 Str

全部评论 (0)

还没有任何评论哟~