zoukankan      html  css  js  c++  java
  • 华为机试——统计排序

    C_C++_WY_01. 统计排序

    • 题目描述:

    编写一个函数,计算出字符串中各种字母(a~z,A~Z)的个数,AABB输出A2B2,aabbCCAAA输出A3C2a2b2,输出结果需要按照字母排序(大写的比小写的排在前面)

    • 要求实现函数:

    void vConvertMsg(char *pInputStr, long lInputLen, char *pOutputStr);

    【输入】

    char *pInputStr:指向一个数组的指针

    long lInputLen:该数组的长度

    char *pOutputStr:指向一块输出的内存,''作为字符串结束符

    【返回】 无

    【注意】 只需要完成该函数功能算法,中间不需要有任何IO的输入输出

    • 示例

    输入:qeddwqrAatt

    返回:A1a1d2e1q2r1t2w1

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42

    #include <iostream>
    #include <string.h>
    using namespace std;
     
     
    void vConvertMsg(char *pInputStr, long lInputLen, char *pOutputStr)
    {
        if ((pInputStr == NULL) || (lInputLen <= 0))
        {
            return;
        }
     
        int alpha[128] = {0};
     
        for (int i = 0; i < lInputLen; i++)
        {
            alpha[*pInputStr]++;
            pInputStr++;
        }
     
        for (int j = 0; j < 128; j++)
        {
            if (alpha[j] != 0)
            {
                *pOutputStr = j;
                pOutputStr++;
                *pOutputStr = alpha[j] + '0';
                pOutputStr++;
            }
        }
     
        *pOutputStr = '';
    }
     
    int main() {
     
        char *pInputStr = "qeddwqrAatt";
        char pOutputStr[30];
        vConvertMsg(pInputStr, strlen(pInputStr), pOutputStr);
        cout << pOutputStr << endl;
        return 0;
    }
  • 相关阅读:
    SSRS_NOTE
    github快速使用指南
    Serving 404s instead of errors solved :)
    如何提高LINQtoSQL延时加载的性能
    SqlServer开发利器—SQL Prompt5
    内核通知链 学习笔记 arm
    Excel报表之js版
    JS修改Table中Td的值。
    什么时候能忙完~
    JS修改Table中Td的值(修改)
  • 原文地址:https://www.cnblogs.com/helloweworld/p/3200270.html
Copyright © 2011-2022 走看看