谁给我想想,这个算法怎么写最简洁啊:
如 有时间段 8:00----12:00 13:00---17:00 18:00-----20:00
另有时间 X = 13:50
如何算出这个X 时间 是在以上时间段的哪个时段之内呢?
要把上面的时间段 分成 1: 00:00----7:59 2: 8:00----12:00
3: 12:01----12:59 4: 13:00----17:00 5: 17:01----17:59
6: 18:00---20:00 7: 20:01----23:59
这样算出来的时段该在1,2,3,4,5,6,7之中的某一个?
高手赐教。
如 有时间段 8:00----12:00 13:00---17:00 18:00-----20:00
另有时间 X = 13:50
如何算出这个X 时间 是在以上时间段的哪个时段之内呢?
要把上面的时间段 分成 1: 00:00----7:59 2: 8:00----12:00
3: 12:01----12:59 4: 13:00----17:00 5: 17:01----17:59
6: 18:00---20:00 7: 20:01----23:59
这样算出来的时段该在1,2,3,4,5,6,7之中的某一个?
高手赐教。
STR_X:STRING;
STR_8_12:STRING;
STR_13_17:STRING;
STR_18_20:STRING;
I:INTEGER;
BEGIN
STR_X:=COPY(X,1,2);
STR_8_12:=COPY('8:00----12:00',1,2);
STR_13_17:=COPY('13:00----17:00',1,2);
STR_18_20:=COPY('18:00----20:00',1,2);
IF STR_X=STR_8_12 THEN I:=1
ELSE IF STR_X=STR_13_17 THEN I:=2
ELSE IF STR_X=STR_18_20 THEN I:=3
ESLE I:=0;
IF I=0 THEN SHOWMESSAGE('NOT IN ANY');
IF I=1 THEN SHOWMESSAGE('IN 8-12');
IF I=2 THEN SHOWMESSAGE('IN 13-17');
IF I=3 THEN SHOWMESSAGE('IN 18-20');
END;
a:integer;
b:integer;
c:integer;
x:real;
begin
a:=trunc(x);
b:=trunc(x*100-a*100);
if a<8 then c:=1
else if (a>=8) and (a<12) then c:=2
else if (a=12) and (b=0) then c:=2
else if (a=12) and (b<>0) then c:=3
else if (a>=13) and (a<17) then c:=4
else if (a=17) and (b=0) then c:=4
else if (a=17) and (b<>0) then c:=5
else if (a>=18) and (a<20) then c:=6
else if (a=20) and (b=0) then c:=6
else c:=7
end.
testch:array[0..2359] of char;
begin
fillchar(testch[0],759-0+1,'1');//1: 00:00----7:59
fillchar(testch[800],1200-800+1,'2');//2: 8:00----12:00
fillchar(testch[1201],1259-1201+1,'3');//3: 12:01----12:59
fillchar(testch[1300],1700-1300+1,'4');//4: 13:00----17:00
fillchar(testch[1701],1759-1701+1,'5');//5: 17:01----17:59
fillchar(testch[1800],2000-1800+1,'6');//6: 18:00---20:00
fillchar(testch[2001],2359-2001,'7');//7: 20:01----23:59
result:=TestCh[700];//7:00属于哪个
//支持256个时间断
end;