大家能帮我看看下面那段算法吗?

来源:百度知道 编辑:UC知道 时间:2024/05/23 00:07:29
输入一个字符串,串内有数字和非数字字符。例如:
a30bc2345 345rf678jk945
将其中连续的数字串转化为整数,存放到单链表中,统计出字符串中的整数个数,并输出这些整数。
#include <iostream>
#include <cmath>
using namespace std;

struct node{
int data;
node *next;
};

void Input(char *s,int n)
{s=new char[n];
cin.getline(s,n);
}

void pickup(char *s,int *a,int n)
{int k=0,z=0;
int sum,h;
sum=0;
int b[50];
for(int i=0;i<n;i++)
{if(int(s[i])>=65&&int(s[i])<=90||int(s[i])>=97&&int(s[i])<=122) {continue;}
else
{k++;
if(int(s[i+1])>=65&&int(s[i+1])<=90||int(s[i+1])>=97&&int(s[i+1])<=122) {};
else
{for(int j=0;j<k+1;j++)
{b[j]=s[i-k+j]*pow(10,k-1-j);
}
for(int m=0;m<k+1;m++)
{sum=sum+b[m];
}
h=0;
a[h]=sum;
h++;
}
}
}
}

node * Head_Creat(a)
{node *head,*n;

楼主看书啦,,基础基础基础,,,改死我了,,
#include <iostream>
#include <cmath>
using namespace std;

struct node
{
int data;
node *next;
};

void MakeNode(char *nbegin,char *nend,node *head);

void pickup(char *s,node *head)
{
char *chtmp;
char *nbegin,*nend;
int noption;

noption = 0;

for (chtmp = s; ; chtmp++)
{
if ((noption == 0) && (*chtmp >= '0' && *chtmp <= '9'))
{
nbegin = chtmp;
noption = 1;
}
else if((noption == 1) && (*chtmp <'0' || *chtmp > '9'))
{
nend = chtmp-1;
MakeNode(nbegin,nend,head);
noption = 0;
if (*chtmp == '\0')
{
break;
}

}
}

}

node * Creat()
{
node *head;

head = new node;
head->data = -1;
head->next =