一道筆試題目(實習)
- 筆試
- 關注:7.89K次
用C/C++寫一個函數,它的`原形是int continumax(char *outputstr,char *intputstr) 功能:在字符串中找出連續最長的數字串,返回這個串的長度,並把這個最長的數字串付給其中一個函數參數outputstr所指內存。例如:"abcd12345ed125ss123456789"的首地址傳給inputstr後,函數將返回9,outputstr所指的值為123456789。
#include
#include
#include
int continumax(char *outputstr,char *inputstr){
if((outputstr==NULL)||(inputstr==NULL))
return 0;
char *current=inputstr;
char *max_start=NULL;
int len=0,max_len=0,ret_len=0;
while(true)
{
if((*current>=)&&(*current<=9)){
len++;
}
else{
if(len>max_len){
max_len=len;
max_start=current-len;
}
len=0;
}
if(*current==)
{
break;}
current++;
}
ret_len=max_len;
outputstr[max_len]=;
while(max_len--)
*outputstr++=*max_start++;
return ret_len;
}
void main()
{char stra[]="abcd12345ed125ss123456789";
char strb[50];
printf("%dn",continumax(strb,stra));
printf("%sn",strb);
}
STYLE="FonT-FAMiLY:"
- 文章版權屬於文章作者所有,轉載請註明 https://xuewengu.com/flzc/bishi/dvo0rq.html