#include <stdio.h>
#include <string.h>
int foo(int d[] , const char s[])
{
int i , k ;
for(i = k = 0 ; s[i] ; k ++) {
for(; s[i] && (s[i] == ' ' || s[i] == '\t' || s[i] == ',') ; i ++) ;
sscanf(& s[i] , "%d" , & d[k]) ;
for(; s[i] && s[i] != ' ' && s[i] != '\t' && s[i] != ',' ; i ++) ;
}
return k ;
}
int main(void)
{
char s[512] ;
int d[200] , e[200] , i , k , n , m ;
printf("input k : ") ;
scanf("%d" , & k) ;
fflush(stdin) ;
printf("input second line : ") ;
gets(s) ;
n = foo(d , s) ;
printf(" input third line : ") ;
gets(s) ;
m = foo(e , s) ;
printf("k = %d\n" , k) ;
printf("the second line is : %d" , d[0]) ;
for(i = 1 ; i < n ; i ++) printf(",%d" , d[i]) ;
printf("\n") ;
printf(" the third line is : %d" , e[0]) ;
for(i = 1 ; i < m ; i ++) printf(",%d" , e[i]) ;
printf("\n\n") ;
}
编译运行实况:D:\[00.Exerciese.2022]\C>g++ -o x x.c
D:\[00.Exerciese.2022]\C>x
input k : 1088
input second line : 1 3 5 7 9 11 13 15 17 19 21
input third line : 2 4 6 8 10 12 14 16 18 20 22
k = 1088
the second line is : 1,3,5,7,9,11,13,15,17,19,21
the third line is : 2,4,6,8,10,12,14,16,18,20,22
D:\[00.Exerciese.2022]\C>
|