Home > Back-end >  Have a class C, geometry. A freshman for help
Have a class C, geometry. A freshman for help

Time:02-06

7 to 18 have class geometry (10)
Xiao Ming saw a course on the schedule of weekly in class is marked as 1, 8, 12-17, 3-6, would you please write a program that will input from the input devices such as the similar weekly said string, converted into standard weekly said,

Input format:
A digital said a week, the middle of the two Numbers - Numbers separated said one week time interval, a - b said range [a, b], procedures to ensure a
The output format:
From small to large, the order of the output with weeks of the course by commas between weeks and weeks, finally no comma,

Input the sample:
3-5,8,13-15,17,10-12
13 to 18, 5-9
3-13, 13-17
The output sample:
3,4,5,8,10,11,12,13,14,15,17
5,6,7,8,9,13,14,15,16,17,18
3,4,5,6,7,8,9,10,11,12,13,14,15,16,17

CodePudding user response:

//input format: 
//a digital said a week, the middle of the two Numbers - Numbers separated said one week time interval, a - b said range [a, b], procedures to ensure a//
//output format:
//from the order of the output course weekly, comma-separated between weeks and weeks, finally no comma,
//
//input sample:
//3-5,8,13-15,17,10-12
//13 to 18, 5-9
//3-13, 13 to 17
//output sample:
//3,4,5,8,10,11,12,13,14,15,17
//5,6,7,8,9,13,14,15,16,17,18
//3,4,5,6,7,8,9,10,11,12,13,14,15,16,17
#include
#include
#include
Const int maxln=100;
Char a, [maxln] [21].
Char ln [maxln] [80];
char *p;
Int N, I, j, k, u, N, f, s, t,
Int main () {
N=0;
While (1) {
If (NULL==the fgets (ln [N], 80, stdin)) break;
If (=='\ n' ln [n] [0]) break;
N++;
If (N>=maxln) break;
}

For (I=0; i
For (I=0; iP=& amp; Ln [I] [0];
S=1;
While (1) {
K=sscanf (p, "% d % n, & amp; U, & amp; n);
//printf (" k, u, n=% d, % d, % d \ n ", k, u, n);
If (1)==k {
If (1==s) {f=u; T=u; S=2; }
Else if (uThe else {t=u; S=1; }
P +=n;
{} else if (0==k)
//printf (" skip char [c] % \ n ", p [0]).
If (', '==p [0]) {
//printf (" f - t: % d, % d \ n ", f, t);
For (j=f; J<=t; J++) a [I] [j]=1;
S=1;
}
P++;
} else {//EOF==k
EOF f - t://printf (" % d, % d \ n ", f, t);
For (j=f; J<=t; J++) a [I] [j]=1;
break;
}
}
N=0;
For (j=1; J<=20; J++)
If (1==a [I] [j]) {
If (0==n) {
Printf (" % d ", j);
N++;
} else {
Printf (" % d ", j);
}
}
printf("\n");
}
return 0;
}