Joined: Tue Mar 27, 2007 10:55 pm Posts: 2272 Location: Earth Has thanked: 39 time Have thanks: 61 time
Years ago, Brian Redman amused the entire networking community by asking on a newsgroup, ``What time is it? E-mail me and I'll summarize to the net.'' Ha ha.
Write a program to convert a time expressed as hour:minute to the (stylized, see below) American english language version of the time. Here are the rules to implement (note that they might be different from what you are used to and are certainly different from British rules):
* Capitalize the first letter of the output * Compound english numbers are hyphenated, e.g.: forty-four * Express x:00 as [x_in_english] o'clock * Express x:15 as Quarter past [x_in_english] * Express x:30 as [x_in_english] thirty * Express x:45 as Quarter to [next_hour_in_english] * Otherwise, express x:nn as: o [x_in_english] [nn_in_english] when nn<45 o [60-nn_in_english] to [next_hour_in_english] when nn>45
Examples:
* 5:00 Five o'clock * 10:10 Ten ten * 9:22 Nine twenty-two * 5:15 Quarter past five * 2:30 Two thirty * 6:40 Six forty * 5:45 Quarter to six * 8:47 Thirteen to nine
PROGRAM NAME: clock INPUT FORMAT A single line with a time expressed as hour:minutes. Each hour is in the range 1..12; minutes are always expressed in two digits and are in the range 0..59 SAMPLE INPUT (file clock.in) 5:45 OUTPUT FORMAT A single line with the time expressed as English. SAMPLE OUTPUT (file clock.out)
int hr=0,min=0,k; for (k=0; st[k]!=':'; k++) hr=hr*10+st[k]-'0'; for (k++; k<st.size(); k++) min=min*10+st[k]-'0';
string timer; int nexthr=(hr+1)%12; if (nexthr==0) nexthr=1; if (min==0) timer=noeng(hr)+" o'clock"; else if (min==15) timer="Quarter past "+noeng(hr); else if (min==30) timer=noeng(hr)+" thirty"; else if (min==45) timer="Quarter to "+noeng(nexthr); else if (min<45) timer=noeng(hr)+" "+noeng(min); else if (min>45) timer=noeng(60-min)+" to "+noeng(nexthr); if ((timer[0]>='a') && (timer[0]<='z')) timer[0]=timer[0]-'a'+'A'; fout << timer << endl; fout.close(); }
_________________ Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )