#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int function1(char *str, int len, int *num);
int function2(char *str, int len, int *num);
int main()
{
char str[100];
gets(str);
int num[100], k = 0;
int len = strlen(str);
k = function2(str, len, num);
for(int i = 0; i < k; i++)
printf("%d\n", num[i]);
return 0;
}
int function1(char *str, int len, int *num)
{
int k = 0, sum, i, j;
for(i = 0; i < len; i++)
{
if(str[i] >= '0' && str[i] <= '9')
{
sum = str[i] - '0';
for(j = i + 1; j < len && (str[j] >= '0' && str[j] <= '9'); j++)
{
sum = sum * 10 + str[j] - '0';
i = j;
}
num[k++] = sum;
}
}
return k;
}
int function2(char *str, int len, int *num)
{
int k = 0, sum, i, j;
for(i = 0; i < len; i++)
{
if(str[i] < '0' || str[i] > '9')
str[i] = ' ';
}
char *pch = strtok(str, " ");
while(pch)
{
num[k++] = atoi(pch);
pch = strtok(NULL, " ");
}
return k;
}
|