2015年华为上机实习(济南)

题目一:
将输入字符串中,紧接数字的第一个连续多次(2或以上)出现的字母去掉一个。如输入 325abbcddaf678ffrtssh,输出325abcddaf678frtssh

/*
 * test.cpp
 *
 *  Created on: 2015年5月6日
 *      Author: zhangjun
 */
#include<stdio.h>
#include<string.h>
#define MAX 1000
int isdig(char a)
{
   	if(a>'0'&&a<'9')
		      return 1;
	   else
      		return 0;
}
int main()
{
   	char data[MAX];
	   char result[MAX];
	   scanf("%s", data);
	   int len = strlen(data);
	   int i;
	   int label = 0;
	   int j = 0;
	   for( i = 0; i < len; i++)
	   {
		      if(isdig(data[i]))
			      label = 1;
		      if((label == 1)&&!(isdig(data[i]))&&(data[i]==data[i-1]))
		      {
			         label = 0;
			         continue;
		      }
		      else
			         result[j++] = data[i];
	   }
   	result[j] = 0;
	   printf("%sn", result);
	   return 0;
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *