<C/C++面试>华为13/14年校园招聘机试题

一,华为13年校招


试题1:

题目描述:  

通过键盘输入任意一个字符串序列,字符串可能包含多个子串,子串以空格分隔。

请编写一个程序,自动分离出各个子串,并使用’,’将其分隔,并且在最后也补充一个’,’并将子串存储。 

如果输入“abc def gh i    d”,结果将是abc,def,gh,i,d, 


要求实现函数:  

void DivideString(const char *pInputStr, long lInputLen, char *pOutputStr); 

【输入】 pInputStr:  输入字符串 

                 lInputLen:  输入字符串长度          

【输出】 pOutputStr: 输出字符串,空间已经开辟好,与输入字符串等长; 

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


示例  

输入:“abc def gh i    d” 输出:“abc,def,gh,i,d,”


<pre name="code" class="html">// ConsoleAppDivideString.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include "iostream"
void DivideString(const char *pInputStr, long lInputLen, char *pOutputStr); 
using namespace std;

#define  MAX 32

int _tmain(int argc, _TCHAR* argv[])
{
	char srcStr[MAX]="abc def gh i  d";
	char dstStr[MAX]={0};
	int len=strlen(srcStr);
	DivideString(srcStr,len,dstStr);
	cout<<"处理后的结果为:"<<dstStr<<endl;
	system("pause");
	return 0;
}

void DivideString(const char *pInputStr, long lInputLen, char *pOutputStr)
{
	int len=lInputLen;
	int i=0;
	while (i<len)
	{
		if (pInputStr[i]==' ')
		{
			pOutputStr[i]=',';
		}
		else
		{
			pOutputStr[i]=pInputStr[i];
		}
		i++;
	}
	int j=0;
	while( j<len )
	{
		if ((pInputStr[j]==' ') && (pInputStr[j+1]==' '))
		{
			for (int k=j;k<len;k++)
			{
				pOutputStr[k+1]=pOutputStr[k+2];
			}
		} 
		j++;
	}
	
	int n=0;
	while (true)
	{
		n++;
		if (pOutputStr[n]=='\0')
		{
			pOutputStr[n]=',';
			pOutputStr[n+1]='\0';
			break;
		}
		
	}
	
}

 
 

另一份可参考答案:

void DivideString(const char *pInputStr, long lInputLen, char *pOutputStr)
{
	long j = 0; 
	for(long i=0;i<lInputLen;i++) 
	{ 
		if(pInputStr[i]!=' ')   
		{ 
			pOutputStr[j]= pInputStr[i];      
			j++;   
		}
		else 
		{ 
				if(pOutputStr[j-1]!= ',')  
				{ 
					pOutputStr[j]=',';    
					j++;   
				}
		}  
	} 
	int n=0;
	while (true)
	{
		n++;
		if (pOutputStr[n]=='\0')
		{
			pOutputStr[n]=',';
			pOutputStr[n+1]='\0';
			break;
		}

	}
}

试题2:

题目描述:  
将输入的一个单向链表,逆序后输出链表中的值。链表定义如下: 

<span style="font-size:18px;">typedef struct tagListNode
 { 
	int value; 
	struct tagListNode *next; 
}ListNode; </span>

要求实现函数:  
void converse(ListNode **head); 

【输入】head:    链表头节点,空间已经开辟好 

【输出】head:    逆序后的链表头节点 【返回】无 

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

示例  

输入:链表  1->2->3->4->5 的头节点head 输出:链表  5->4->3->2->1 的头节点head


<pre name="code" class="html">// ConsoleAppConverseList.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>  
#include<cassert>  

using namespace std;  

typedef struct tagListNode  
{  
	int value;  
	struct tagListNode *next;  
}ListNode;  //节点 

void Reverse(ListNode **phead)  //反序链表元素
{  
	if ((*phead)==NULL)
	{
		cout<<"No Data"<<endl;
		return;
	}
	ListNode *preNode=NULL;
	ListNode *curNode=*phead;
	while(curNode->next!=NULL)    
	{    
		ListNode *temp=curNode->next;    
		curNode->next=preNode;    
		preNode=curNode;    
		curNode=temp;    
	}    
	//对最后个节点处理
	curNode->next = preNode;    
	*phead=curNode;
	

	
}  
void Insert(ListNode **phead,int nData)  //插入链表元素
{  
	ListNode *newNode=new ListNode;
	assert(newNode); 
	newNode->value=nData;
	newNode->next=NULL;

	if ((*phead)==NULL)
	{
		*phead=newNode;
	}
	else
	{
		newNode->next=*phead;
		*phead=newNode;
	}
}  
void PrintList(ListNode **phead)  //打印链表元素
{  
	ListNode *p=*phead;
	if (p==NULL)
	{
		cout<<"No Data!!!"<<endl;
		return;
	}

	for (;p!=NULL;p=p->next)
	{
		cout<<p->value<<"->";
	}
	cout<<endl; 
}  

int  LengthList(ListNode **phead)  //打印链表元素
{  
	int count=0;

	ListNode *p=*phead;
	if (p==NULL)
	{
		cout<<"No Data!!!"<<endl;
		return 0;
	}

	for (;p!=NULL;p=p->next)
	{
		count++;
	}
	return count;
}  


void DelNode(ListNode **phead,int nDate)
{
	ListNode *preNode=NULL;
	ListNode *curNode=*phead;

	if (curNode->value==nDate)
	{
		*phead=curNode->next;//为什么不能用curNode=curNode->next;?????????
	}
	else
	{
		while(curNode->value!=nDate)
		{
			preNode=curNode;
			curNode=curNode->next;
			if (curNode->value==nDate)
			{
				preNode->next=curNode->next;
				delete curNode;
				break;
			}

		}
	}


}

int _tmain(int argc, _TCHAR* argv[])
{  
	ListNode *head=new ListNode; 
	head=NULL;
	Insert(&head,5);
	Insert(&head,1);
	Insert(&head,3);
	Insert(&head,4);
	PrintList(&head);
	int len=LengthList(&head);
	cout<<"Length of List: "<<len<<endl;
	DelNode(&head,4);
	Reverse(&head);
	PrintList(&head);
	getchar();
	return 0;
}
 

二,华为14年校招

试题1:

输入1--50个数字,求出最小数和最大数的和,输入以逗号隔开 

[html]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. <pre name="code" class="html">// ConsoleAppMaxMinSum.cpp : 定义控制台应用程序的入口点。  
  2. //  
  3.   
  4. #include "stdafx.h"    
  5. #include "iostream"    
  6.   
  7. using namespace std;    
  8.   
  9. #define MAX 50    
  10. void BubbleSort(int pArr[],int n) ;    
  11. int _tmain(int argc, _TCHAR* argv[])    
  12. {    
  13.     int n=0;    
  14.     int a[MAX]={0};    
  15.     char str=',';       
  16.   
  17.     cout<<"你想输入多少个整数?(注:请不要超过50个数字)"<<endl;    
  18.     cin>>n;    
  19.     if (n>=50)    
  20.     {    
  21.         cout<<"请不要超过50个数字,请重新输入:"<<endl;    
  22.         cin>>n;    
  23.     }    
  24.     cout<<"请输入具体数字,并以逗号隔开:"<<endl;     
  25.   
  26.     for (int i=0;i<n;i++)    
  27.     {    
  28.         if (i==n-1)    
  29.             cin>>a[i];    
  30.         else    
  31.             cin>>a[i]>>str;    
  32.     }     
  33.       
  34.     BubbleSort(a,n);    
  35.     cout<<"排序后的数组为: "<<endl;    
  36.     for (int i=0;i<n;i++)    
  37.     {    
  38.         cout<<a[i]<<" ";    
  39.     }    
  40.     cout<<endl;    
  41.     cout<<"最小值与最大值的和为:"<<a[0]+a[n-1];    
  42.     cout<<endl;    
  43.     system("pause");    
  44.     return 0;    
  45. }    
  46.   
  47.   
  48. void BubbleSort(int *pArr,int n)    
  49. {    
  50.     for (int i=0;i<n;i++)  
  51.     {  
  52.         for (int j=i+1;j<n;j++)  
  53.         {  
  54.             if (pArr[j]>pArr[i])  
  55.             {  
  56.                 int temp=0;  
  57.                 temp=pArr[j];  
  58.                 pArr[j]=pArr[i];  
  59.                 pArr[i]=temp;  
  60.             }  
  61.         }  
  62.     }  
  63. }  

 

另一份我认为更有价值的答案:

[html]  view plain copy print ?
  1. #include<stdio.h>      
  2. #define N 50      
  3. void Sort(int a[],int n);      
  4. int main(void)      
  5. {          
  6.     char str[100];      
  7.     int a[N]={0};      
  8.     gets_s(str);      //要点1:动态的输入1--50个整数,不能确定个数,只能用字符串输入,然后分离出来      
  9.     int i=0,j=0;      
  10.     int sign=1;      
  11.     while(str[i]!='\0')    //是末尾则终止  
  12.     {      
  13.         if(str[i]!=',')  //输入时要在半角输入,首先判断是否是逗号      
  14.         {      
  15.   
  16.             if(str[i] == '-')    //要点:2:有负整数的输入    ,在判断是否是负号  
  17.             {      
  18.                 // i++;   //易错点1      
  19.                 sign=-1;      
  20.             }      
  21.             else if(str[i]!='\0'||str[i]!=',') //不用else的话,负号也会减去‘0’      
  22.             {      
  23.                 a[j]=a[j]*10 + str[i]-'0'; //要点3:输入的可以是多位数      
  24.   
  25.             }      
  26.         }      
  27.         i++;      
  28.         if(str[i]==',' || str[i]=='\0')  //这个判断是在i自加以后      
  29.         {      
  30.             a[j]=a[j]*sign;  //易错点2      
  31.             sign=1;   易错点3      
  32.             j++;    //j就是a数组的个数 范围0到j-1      
  33.         }      
  34.     }      
  35.   
  36.     Sort(a,j);    //排序  
  37.     printf("Max number + Min number = %d",a[0]+a[j-1]);      
  38.     getchar();  
  39.     return 0;      
  40. }      
  41. void Sort(int a[],int n)  //选择排序      
  42. {      
  43.     int i,j;      
  44.     int k;      
  45.     int temp;      
  46.     for(i=0;i<n-1;i++)      
  47.     {      
  48.         k=i;      
  49.         for(j=i+1;j<n;j++)      
  50.         {      
  51.             if(a[k]>a[j])      
  52.                 k=j;      
  53.         }      
  54.         if(i!=k)      
  55.         {      
  56.             temp = a[k];      
  57.             a[k] = a[i];      
  58.             a[i] = temp;      
  59.         }      
  60.     }      
  61.     for(i=0;i<n;i++)      
  62.         printf("%-5d",a[i]);      
  63.     puts("");      
  64. }      

试题2:

通过键盘输入100以内正整数的加、减运算式,请编写一个程序输出运算结果字符串。

输入字符串的格式为:“操作数1 运算符 操作数2”,“操作数”与“运算符”之间以一个空格隔开。

补充说明:

1、操作数为正整数,不需要考虑计算结果溢出的情况。

2、若输入算式格式错误,输出结果为“0”。

要求实现函数: 

void arithmetic(const char *pInputStr, long lInputLen, char *pOutputStr);

【输入】 pInputStr:  输入字符串

              lInputLen:  输入字符串长度         

【输出】 pOutputStr: 输出字符串,空间已经开辟好,与输入字符串等长; 

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

示例 

输入:“4 + 7”  输出:“11”

输入:“4 - 7”  输出:“-3”

输入:“9 ++ 7”  输出:“0” 注:格式错误

[html]  view plain copy print ?
  1. #include "stdafx.h"  
  2. #include "iostream"  
  3. #include <stdlib.h>  
  4. #define MAX 10   
  5. using namespace std;  
  6.   
  7. void help()  
  8. {  
  9.     cout<<"注意:"<<endl;  
  10.     cout<<"     1,操作数”与“运算符”之间以一个空格隔开。"<<endl;  
  11.     cout<<"     2,操作数为正整数,不需要考虑计算结果溢出的情况。"<<endl;  
  12.     cout<<"     3,若输入算式格式错误,输出结果为“0”。"<<endl;  
  13.     cout<<endl;  
  14.     cout<<"请输入格式为:“操作数1 运算符 操作数2”的字符串(不包括引号)"<<endl;  
  15. }  
  16.   
  17. void Arithmetic(const char *pInputStr, long lInputLen, char *pOutputStr);  
  18.   
  19.   
  20. int _tmain(int argc, _TCHAR* argv[])  
  21. {  
  22.     help();  
  23.     char srcStr[MAX]="71 + 4";  
  24.     char outStr[MAX]={0};  
  25.     int len=0;  
  26.     gets_s(srcStr);  
  27.     len=strlen(srcStr);  
  28.     Arithmetic(srcStr,len,outStr);  
  29.     cout<<outStr;  
  30.     getchar();  
  31.     return 0;  
  32. }  
  33.   
  34. void Arithmetic(const char *pInputStr, long lInputLen, char *pOutputStr)  
  35. {  
  36.     const char *input = pInputStr;      
  37.     char *output = pOutputStr;      
  38.     char oper[MAX]={0};  
  39.     int i=0,j=0,k=0;  
  40.     int num[MAX]={0};  
  41.     while (input[i]!='\0')  
  42.     {  
  43.         while (input[i]!=' ')  
  44.         {  
  45.             num[j]=num[j]*10+input[i]-'0';  
  46.             i++;  
  47.         }  
  48.   
  49.         for (;('0'>= input[i])||('9'<=input[i]);i++,k++)  
  50.         {  
  51.             oper[k]=input[i];  
  52.         }  
  53.         j++;  
  54.         while(input[i]!='\0')  
  55.         {  
  56.             num[j]=num[j]*10+input[i]-'0';    
  57.             i++;  
  58.         }  
  59.     }  
  60.   
  61.     int sum=0;  
  62.     for (int m=0;m<=k;m++)  
  63.     {  
  64.         sum=sum+oper[m];  
  65.     }  
  66.   
  67.     switch (sum)  
  68.     {  
  69.     case 107:  
  70.         _itoa_s(num[0]+num[1],pOutputStr,10,10);    
  71.         break;  
  72.     case 109:  
  73.         _itoa_s(num[0]-num[1],pOutputStr,10,10);    
  74.         //*pOutputStr=char(num[0]-num[1]);  
  75.         break;  
  76.     default:  
  77.         output[0] = '0';      
  78.         return;  
  79.     }  
  80. }  

另一份我认为比较有价值的答案:

[html]  view plain copy print ?
  1. #include <iostream>      
  2.       
  3. using namespace std;      
  4.       
  5. void arithmetic(const char *pInputStr, long lInputLen, char *pOutputStr)      
  6. {      
  7.  const char *input = pInputStr;      
  8.        char *output = pOutputStr;      
  9.  int sum = 0;      
  10.  int operator1 = 0;      
  11.  int operator2 = 0;      
  12.  char *temp = new char[5];      
  13.  char *ope = temp;      
  14.  while(*input != ' ') //获得操作数1      
  15.  {      
  16.      sum = sum*10 + (*input++ - '0');      
  17.  }      
  18.  input++;      
  19.  operator1 = sum;      
  20.  sum = 0;      
  21.       
  22.  while(*input != ' ')      
  23.  {      
  24.      *temp++ = *input++;      
  25.  }      
  26.       
  27.  input++;      
  28.  *temp = '\0';      
  29.       
  30.  if (strlen(ope) > 1 )      
  31.  {      
  32.      *output++ = '0';      
  33.      *output = '\0';      
  34.      return;      
  35.  }      
  36.       
  37.  while(*input != '\0') //获得操作数2      
  38.  {      
  39.      sum = sum*10 + (*input++ - '0');      
  40.  }      
  41.  operator2 = sum;      
  42.  sum = 0;      
  43.       
  44.  switch (*ope)      
  45.  {      
  46.  case '+':itoa(operator1+operator2,pOutputStr,10);      
  47.      break;      
  48.  case '-':itoa(operator1-operator2,pOutputStr,10);      
  49.     break;      
  50.  default:      
  51.      *output++ = '0';      
  52.      *output = '\0';      
  53.      return;      
  54.  }      
  55. }      
  56.       
  57. int main()      
  58. {      
  59.     char input[] = "4 - 7";      
  60.     char output[] = "    ";      
  61.     arithmetic(input,strlen(input),output);      
  62.     cout<<output<<endl;      
  63.     return 0;      
  64. }      

试题3:

1.通过键盘输入一串小写字母(a~z)组成的字符串。请编写一个字符串过滤程序,若字符串中出现多个相同的字符,将非首次出现的字符过滤掉。

比如字符串“abacacde”过滤结果为“abcde”。

要求实现函数:void stringFilter(constchar *pInputStr, long lInputLen, char *pOutputStr);

【输入】 pInputStr:  输入字符串

           lInputLen:  输入字符串长度         

【输出】 pOutputStr: 输出字符串,空间已经开辟好,与输入字符串等长; 

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

示例 

输入:“deefd”       输出:“def”

输入:“afafafaf”     输出:“af”

输入:“pppppppp”     输出:“p”

main函数已经隐藏,这里保留给用户的测试入口,在这里测试你的实现函数,可以调用printf打印输出

当前你可以使用其他方法测试,只要保证最终程序能正确执行即可,该函数实现可以任意修改,但是不要改变函数原型。

一定要保证编译运行不受影响

[html]  view plain copy print ?
  1. #include "stdafx.h"  
  2. #include <iostream>      
  3. #include <cassert>      
  4.   
  5. using namespace std;    
  6. bool g_flag[26];    
  7.   
  8. void stringFilter(const char *pInputStr, long lInputLen, char *pOutputStr);  
  9.   
  10. int _tmain(int argc, _TCHAR* argv[])  
  11. {  
  12.     memset(g_flag,0,sizeof(g_flag));      
  13.     char input[] = "abacacde";      
  14.     char *output = new char[strlen(input) + 1];      
  15.     stringFilter(input,strlen(input),output);      
  16.     cout<<output<<endl;      
  17.     delete output;      
  18.     return 0;      
  19.   
  20. }  
  21.   
  22.   
  23. <pre name="code" class="html">void stringFilter(const char *pInputStr, long lInputLen, char *pOutputStr)  
  24. {  
  25.     const char *input = pInputStr;      
  26.     char *output = pOutputStr;      
  27.     int len=lInputLen;  
  28.     int i=0,j=0;  
  29.   
  30.     for (;i<len;i++)  
  31.     {   for (j=len-1;j>i;j--)  
  32.         {  
  33.             if (input[i]==input[j])  
  34.                 g_flag[j]=true;  
  35.         }  
  36.     }  
  37.   
  38.     int m=0,n=0;  
  39.         do   
  40.         {  
  41.             if (g_flag[m]==false)  
  42.             {  
  43.                 pOutputStr[n]=input[m];  
  44.                 n++;  
  45.             }  
  46.             m++;  
  47.         } while (m<len);  
  48.         pOutputStr[len-n+1]='\0';  
  49.         /*  
  50.         for (int k=len-n+1;k<len;k++)  
  51.         {  
  52.             pOutputStr[k]='\0';  
  53.         }  
  54.         */  
  55. }  

 

另一份比较有价值的答案:

[html]  view plain copy print ?
  1. #include <iostream>      
  2. #include <cassert>      
  3.       
  4. using namespace std;      
  5.       
  6. bool g_flag[26];      
  7. void stringFilter(const char *pInputStr, long lInputLen, char *pOutputStr)      
  8. {      
  9.   assert(pInputStr != NULL);      
  10.   int i = 0;      
  11.   if (pInputStr == NULL || lInputLen <= 1)      
  12.   {      
  13.       return;      
  14.   }      
  15.   const char *p = pInputStr;      
  16.   while(*p != '\0')      
  17.   {      
  18.      if (g_flag[(*p - 'a')])      
  19.      {      
  20.          p++;      
  21.      }else{      
  22.          pOutputStr[i++] = *p;      
  23.          g_flag[*p - 'a'] = 1;      
  24.          p++;      
  25.      }      
  26.   }      
  27.   pOutputStr[i] = '\0';      
  28. }      
  29. int main()      
  30. {      
  31.     memset(g_flag,0,sizeof(g_flag));      
  32.     char input[] = "abacacde";      
  33.     char *output = new char[strlen(input) + 1];      
  34.     stringFilter(input,strlen(input),output);      
  35.     cout<<output<<endl;      
  36.     delete output;      
  37.     return 0;      
  38. }      

试题4:

通过键盘输入一串小写字母(a~z)组成的字符串。请编写一个字符串压缩程序,将字符串中连续出席的重复字母进行压缩,并输出压缩后的字符串。
压缩规则:
1、仅压缩连续重复出现的字符。比如字符串"abcbc"由于无连续重复字符,压缩后的字符串还是"abcbc"。
2、压缩字段的格式为"字符重复的次数+字符"。例如:字符串"xxxyyyyyyz"压缩后就成为"3x6yz"。
要求实现函数: 
void stringZip(const char *pInputStr, long lInputLen, char *pOutputStr);
【输入】 pInputStr: 输入字符串
lInputLen: 输入字符串长度
【输出】 pOutputStr: 输出字符串,空间已经开辟好,与输入字符串等长;
【注意】只需要完成该函数功能算法,中间不需要有任何IO的输入输出
示例 
输入:“cccddecc” 输出:“3c2de2c”
输入:“adef” 输出:“adef”
输入:“pppppppp” 输出:“8p”


(此代码不能统计超过两位数相邻的,比如有11个a相邻,只能得到1a,而不是11a)

[html]  view plain copy print ?
  1. // ConsoleAppStringZip.cpp : 定义控制台应用程序的入口点。  
  2. //  
  3.   
  4.   
  5. #include "stdafx.h"  
  6. #include "iostream"  
  7.   
  8.   
  9. using namespace std;  
  10. void stringZip(const char *pInputStr, long lInputLen, char *pOutputStr);  
  11.   
  12.   
  13. int _tmain(int argc, _TCHAR* argv[])  
  14. {  
  15.     char input[] = "aaaaaaaaacce";      
  16.     char *output = new char[strlen(input) + 1];      
  17.     stringZip(input,strlen(input),output);      
  18.     cout<<output<<endl;    
  19.     getchar();  
  20.     return 0;      
  21. }  
  22.   
  23.   
  24. void stringZip(const char *pInputStr, long lInputLen, char *pOutputStr)  
  25. {  
  26.       
  27.     const char *input = pInputStr;        
  28.     char *output = pOutputStr;   
  29.   
  30.   
  31.     long len=lInputLen;  
  32.     int k=0,step=0,flag=0;  
  33.     int j=0;  
  34.         for (int i=0;i<len;i++)  
  35.         {     
  36.             step=1;  
  37.             j=i+flag;  
  38.             while (input[j]==input[j+1])  
  39.             {  
  40.                     step++;  
  41.                     flag++;  
  42.                     j++;  
  43.             }  
  44.       
  45.                 output[k]='0'+step%10;  
  46.                 k++;  
  47.                 output[k]=input[j];  
  48.                 k++;  
  49.   
  50.   
  51.                 if (input[j+1]=='\0')  
  52.                 {  
  53.                     output[k]='\0';  
  54.                     break;  
  55.                 }         
  56.         }  
  57. }  

另一份比较有价值的答案:

[html]  view plain copy print ?
  1. #include <iostream>      
  2. #include <cassert>      
  3.       
  4. using namespace std;      
  5.       
  6. void stringZip(const char *pInputStr, long lInputLen, char *pOutputStr)      
  7. {      
  8.   const char *p = pInputStr;      
  9.   int num = 1;      
  10.   int i = 0;      
  11.   p++;      
  12.   while(*p != NULL)      
  13.   {      
  14.       while(*p == *(p-1)&& *p != NULL)      
  15.       {      
  16.        num++;      
  17.        p++;      
  18.       }      
  19.       if (num > 1)      
  20.       {      
  21.            int size = 0;      
  22.            int temp = num;      
  23.            while(num)             //计算位数      
  24.            {      
  25.              size++;      
  26.              num /= 10;      
  27.            }      
  28.            num = 1;      
  29.       
  30.            for (int j = size; j > 0; j--)      
  31.            {      
  32.                pOutputStr[i+j-1] = '0'+ temp%10;      
  33.                temp /= 10;      
  34.            }      
  35.            i +=size;      
  36.            pOutputStr[i++] = *(p-1);      
  37.            p++;      
  38.       }else{      
  39.           pOutputStr[i++] = *(p-1);      
  40.           p++;      
  41.       }      
  42.   }      
  43.   pOutputStr[i] = '\0';      
  44. }      
  45.       
  46. int main()      
  47. {      
  48.     char input[] = "cccddecc";      
  49.     char *output = new char[strlen(input) + 1];      
  50.     stringZip(input,strlen(input),output);      
  51.     cout<<output<<endl;      
  52.     return 0;      
  53. }      

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值