
Thanks
Moderator: Board moderators
Code: Select all
if Start_hour > End_hour
{
if Start_hour is in the day
{
if End_hour is in the day
.......(assign time of day,night,evening)
if End_hour is in the evening
.......
if End_hour is in the night
.......
}
if Start_hour is in the evening
{
if End_hour is in the day
.......(assign time of day,night,evening)
if End_hour is in the evening
.......
if End_hour is in the night
........
}
if Start_hour is in the night
{
if End_hour is in the day
.......(assign time of day,night,evening)
if End_hour is in the evening
.......
if End_hour is in the night
........
}
}
else if Start_hour < End_hour
{
...........(same as above)
}
else
{
if Start_minute > End_minute
.......
else if Start_minute < End_minute
.......
else
........
}
Code: Select all
#include<iostream.h>
#include<string.h>
#define day 8
#define evening 18
#define night 22
char step,phone[8],TimeSH[2],TimeSM[2],TimeEH[2],TimeEM[2];
short int StartH,StartM,EndH,EndM;
short int hour,daysec,nightsec,eveningsec;
float prize;
short int section(short int time)
{
if ((time >= day) && (time < evening))
return 1; /* means time is in day section */
else if ((time >= evening) && (time < night))
return 2; /* means time is in evening section */
else /* means time is in night section */
return 3;
}
void main(void)
{
cout.setf(ios::fixed);
cout.precision(2);
while(cin>>step)
{
if (step == '#')
break;
cin>>phone>>TimeSH>>TimeSM>>TimeEH>>TimeEM;
StartH = (TimeSH[0] - 48) * 10 + TimeSH [1] - 48;
StartM = (TimeSM[0] - 48) * 10 + TimeSM [1] - 48;
EndH = (TimeEH[0] - 48) * 10 + TimeEH [1] - 48;
EndM = (TimeEM[0] - 48) * 10 + TimeEM [1] - 48;
hour = 24 - StartH;
if (StartH > EndH) /* start time > end time */
{
if ((hour < 3)||(hour > 16)) /* start time falls in night section */
{
if (section(EndH) == 1) /* end time falls in day section */
{
eveningsec = 0;
daysec = (EndH - day) * 60 + EndM;
nightsec = (day + (24 - StartH) - 1) * 60 + (60 - StartM);
}
else if (section(EndH) == 2) /* end time falls in evening section */
{
eveningsec = (EndH - evening) * 60 + EndM;
daysec = 600;
nightsec = (day + (24 - StartH) - 1) * 60 + (60 - StartM);
}
else /* end time falls in night section(same as start time) */
{
eveningsec = 240;
daysec = 600;
if ((StartH < day)&&(EndH < day)) /* they all fall after 24:00 */
nightsec = (day - StartH - 1 + EndH + 2) * 60 + (60 - StartM + EndM);
else if ((StartH >= night)&&(EndH >= night)) /* they all fall before 24:00 */
nightsec = (24 - StartH - 1 + EndH - night + day) * 60 + (60 - StartM + EndM);
else /* start time falls before 24:00, end time falls after 24:00 */
{
eveningsec = 0;
daysec = 0;
nightsec = (24 - StartH - 1 + EndH) * 60 + (60 - StartM + EndM);
}
}
}
else if (hour < 7) /* start time falls in evening section */
{
if (section(EndH) == 1) /* end time falls in day section */
{
eveningsec = (night - StartH - 1) * 60 + (60 - StartM);
daysec = (EndH - day) * 60 + EndM;
nightsec = 600;
}
else if (section(EndH) == 2) /* end time falls in evening section */
{
eveningsec = (night - StartH - 1 + EndH - evening) * 60 + (60 - StartM + EndM);
daysec = 600;
nightsec = 600;
}
else /* end time falls in night section */
{
eveningsec = (night - StartH - 1) * 60 + (60 - StartM);
daysec = 0;
nightsec = (EndH + 2) * 60 + (EndM);
}
}
else /* start time falls in day section */
{
if (section(EndH) == 1) /* end time falls in day section */
{
eveningsec = 240;
daysec = (evening - StartH - 1 + EndH - day) * 60 + (60 - StartM + EndM);
nightsec = 600;
}
else /* end time falls in night section */
{
eveningsec = 240;
daysec = (evening - StartH - 1) * 60 + (60 - StartM);
nightsec = (EndH + 2) * 60 + (EndM);
}
}
}
else if (StartH < EndH) /* start time < end time */
{
if ((hour < 3)||(hour > 16)) /* start time falls in night section */
{
if (section(EndH) == 1) /* end time falls in day section */
{
eveningsec = 0;
daysec = (EndH - day) * 60 + EndM;
nightsec = (day - StartH - 1) * 60 + (60 - StartM);
}
else if (section(EndH) == 2) /* end time falls in evening section */
{
eveningsec = (EndH - evening) * 60 + EndM;
daysec = 600;
nightsec = (day - StartH - 1) * 60 + (60 - StartM);
}
else /* end time falls in night section(same as start time) */
{
if (((StartH < day)&&(EndH < day))||((StartH >= night)&&(EndH >= night))) /* they all fall after 24:00 or before 24:00 */
{
eveningsec = 0;
daysec = 0;
nightsec = (EndH - StartH - 1) * 60 + (60 - StartM + EndM);
}
else /* start time falls after 24:00, end time falls before 24:00 */
{
eveningsec = 240;
daysec = 600;
nightsec = (day - StartH - 1 + EndH - night) * 60 + (60 - StartM + EndM);
}
}
}
else if (hour < 7) /* start time falls in evening section */
{
if (section(EndH) == 2) /* end time falls in evening section */
{
eveningsec = (EndH - StartH - 1) * 60 + (60 - StartM + EndM);
daysec = 0;
nightsec = 0;
}
else /* end time falls in night section */
{
eveningsec = (night - StartH - 1) * 60 + (60 - StartM);
daysec = 0;
nightsec = (EndH - night) * 60 + (EndM);
}
}
else /* start time falls in day section */
{
if (section(EndH) == 1) /* end time falls in day section */
{
eveningsec = 0;
daysec = (EndH - StartH - 1) * 60 + (60 - StartM + EndM);
nightsec = 0;
}
else if (section(EndH) == 2) /* end time falls in evening section */
{
eveningsec = (EndH - evening) * 60 + (EndM);
daysec = (evening - StartH - 1) * 60 + (60 - StartM);
nightsec = 0;
}
else /* end time falls in night section */
{
eveningsec = 240;
daysec = (evening - StartH - 1) * 60 + (60 - StartM);
nightsec = (EndH - night) * 60 + (EndM);
}
}
}
else /* start time = end time */
{
if (StartM < EndM) /* start minute < end minute */
{
eveningsec = 0;
daysec = 0;
nightsec = 0;
if (section(StartH) == 1) /* both fall in day section */
daysec = EndM - StartM;
else if (section(StartH) == 2) /* both fall in evening section */
eveningsec = EndM - StartM;
else /* both fall in night section */
nightsec = EndM - StartM;
}
else if (StartM > EndM) /* start minute > end minute */
{
eveningsec = 240;
daysec = 600;
nightsec = 600;
if (section(StartH) == 1) /* both fall in day section */
daysec = 600 - (StartM - EndM);
else if (section(StartH) == 2) /* both fall in evening section */
eveningsec = 240 - (StartM - EndM);
else /* both fall in night section */
nightsec = 600 - (StartM - EndM);
}
else /* start minute = end minute */
{
eveningsec = 240;
daysec = 600;
nightsec = 600;
}
}
switch (step)
{
case 'A':
prize = 0.1 * daysec + 0.06 * eveningsec + 0.02 * nightsec;
break;
case 'B':
prize = 0.25 * daysec + 0.15 * eveningsec + 0.05 * nightsec;
break;
case 'C':
prize = 0.53 * daysec + 0.33 * eveningsec + 0.13 * nightsec;
break;
case 'D':
prize = 0.87 * daysec + 0.47 * eveningsec + 0.17 * nightsec;
break;
default: /* case E */
prize = 1.44 * daysec + 0.8 * eveningsec + 0.3 * nightsec;
}
cout.width(10);
cout<<phone;
cout.width(5);
cout<<daysec;
cout.width(7);
cout<<eveningsec;
cout.width(6);
cout<<nightsec;
cout.width(3);
cout<<step;
cout.width(8);
cout<<prize<<endl;
}
}
What is this kind of things? I figure the input times work on their own.[cpp]StartH = (TimeSH[0] - 48) * 10 + TimeSH [1] - 48;
StartM = (TimeSM[0] - 48) * 10 + TimeSM [1] - 48;
EndH = (TimeEH[0] - 48) * 10 + TimeEH [1] - 48;
EndM = (TimeEM[0] - 48) * 10 + TimeEM [1] - 48; [/cpp]