zoukankan      html  css  js  c++  java
  • 华为笔试题08

    • 题目描述:

    编写一个函数,计算出字符串中各种字母(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

     

    #include "stdafx.h"
    #include <iostream>
    #include <vector>
    #include <map>
    #include <algorithm>
    using namespace std;
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	char str[]="qeddwqrtrewtgreAattzzz";
    	vector<char>a;
    
    	for(int i=0;i<strlen(str);++i)
    		a.push_back(str[i]);	
    	sort(a.begin(),a.end());
    
    	char *out=new char [sizeof(str)];
    	char *out2=new char [sizeof(str)+10];	
    	int i=0,j=0;
    	for(vector<char>::iterator iter=a.begin();iter!=a.end();iter++)
    	{
    		out[i]=*iter;
    		++i;		
    	}
    
    	
    	i=0;
    	int count=1;
    	while(i<strlen(str))
    	{		
    		if(out[i]==out[i+1])
    		{
    			count++;
    			i++;
    		}
    		else
    		{
    			out2[j++]=out[i];
    			out2[j++]=count+'0';			
    			i++;
    			count=1;
    		}
    	}
    	out2[j]='';
    	cout<<out2<<endl;
    	return 0;
    }
    

      

  • 相关阅读:
    小程序 scroll-view 中文字不换行问题
    模块
    网络编程
    元类
    day24
    day23
    day22
    day21
    day18
    day17
  • 原文地址:https://www.cnblogs.com/xd-jinjian/p/3277193.html
Copyright © 2011-2022 走看看