65,187
社区成员




#include <iostream>
using namespace std;
char* cz(const char* str, int len){
int start = 0, zcc = 0, sy = 0;
char * temp;
cout << "cz被调用。" << endl;
for (int k = 0; k < len; k++)
{
char ch;
ch = str[k];
if (ch >= '0' && ch <= '9')
{
sy++;
if (((k >= 1) && ((str[k-1] <= '0' || str[k-1] >= '9'))) || k ==0)
{
start = k;
sy = 1;
}
}else{
if (zcc < sy)
{
zcc = sy;
temp = (char*)(str + start);
sy = 0;
}
}
}
for(char* ls = temp; ls < zcc+temp; ls++)
cout<< *ls;
cout << endl;
cout << "数字串的长度为:" << zcc << endl;
return temp;
}
int main(){
char test[50] = "abc123deeg89m+_345678bnm367";
char* s;
s = cz(test, 27);
cout << "s的开始地址为" << &s << endl;
return 0;
}
#include <iostream>
#include <cstring>
using namespace std;
int maxcontinunum(const char *inputstr,char * outputstr)
{
const char *pFirst=inputstr;
const char *p=inputstr;
int index=0;
int ilastcount=0;
//int icurrentcount=0;
while(*p!='\0')
{
cout<<"----------"<<endl;
int icurrentcount=0;
while((*p!='\0')&&(*p>='A')&&(*p<='z'))
{
// ++index;
++p;
}
while((*p>='0')&&(*p<='9')&&(*p!='\0'))
{
++p;
++icurrentcount;
}
if(icurrentcount>=ilastcount)
{
ilastcount=icurrentcount;
index=p-icurrentcount-pFirst;
}
// ++p;
}
char *pT=const_cast<char*>(pFirst+index);
//strncpy(outputstr,pT,ilastcount);
for(int i=0;i<ilastcount;i++)
*outputstr++=*pT++;
outputstr[ilastcount]='\0';
return ilastcount;
}
int main()
{
char *p=new char[32];
memset(p,0,32);
maxcontinunum("2222222222222222222222222222f122f1215ffa1111111111111111111d21034313fda131321321",p);
cout<<p<<endl;
return 0;
}
#include <iostream>
#include <string>
#include <tchar.h>
#include <cctype>
using namespace std;
int maxcontinunum(const char *inputstr,char ** outputstr)
{
int ret = 0, maxindex = 0;
*outputstr = NULL;
char* ptr = (char*)inputstr;
char* maxptr = NULL;
bool bNotindigit = true;
while (*ptr)
{
if (isdigit(*ptr))
{
if(bNotindigit)
{
*outputstr = ptr;
ret = 1;
bNotindigit = false;
}
else
ret++;
}
else{
bNotindigit = true;
ret>maxindex ? (maxindex = ret,maxptr = *outputstr):(NULL);
}
ptr++;
}
ret>maxindex ? (maxindex = ret,maxptr = *outputstr):(NULL);
return maxindex;
}
int main(){
char* pur = NULL;
int ret = maxcontinunum("123456fakdjf123kjk12345kjkj12d1234567",&pur);
printf("%d %c",ret,*pur);
return 0;
}
#include <iostream>
using namespace std;
char* cz(const char* str, int len){
int start = 0, zcc = 0, sy = 0;
char * temp;
cout << "cz被调用。" << endl;
for (int k = 0; k < len; k++)
{
char ch;
ch = str[k];
if (ch >= '0' && ch <= '9')
{
sy++;
if (((k >= 1) && ((str[k-1] <= '0' || str[k-1] >= '9'))) || k ==0)
{
start = k;
sy = 1;
}
if ((k == len-1) && (zcc < sy))
{
zcc = sy;
temp = (char*)(str + start);
sy = 0;
}
}else{
if (zcc < sy)
{
zcc = sy;
temp = (char*)(str + start);
sy = 0;
}
}
}
for(char* ls = temp; ls < zcc+temp; ls++)
cout<< *ls;
cout << endl;
cout << "数字串的长度为:" << zcc << endl;
return temp;
}
int main(){
// char test[50] = "abc123deeg89m+_345678bnm367";
char test[100] = "abc123abcdef12345abcdefgh123456789";
char* s;
s = cz(test, 34);
cout << "s的开始地址为" << &s << endl;
return 0;
}