Sat Jun 30, 2007 11:02 pm
/*
[u][b]PROG: clock[/b][/u]
*/
/* Ad hoc problem */
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
char *tens[]={"twenty","thirty","forty","fifty"};
char *ones[]={"","one","two","three","four","five","six","seven","eight","nine"};
char *pten[]={"ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen",
"eighteen","nineteen"};
string noeng(int no)
{
if ((no>0) && (no<10)) return ones[no];
if ((no>=10) && (no<20)) return pten[no-10];
string ab;
ab=string(tens[(int)(no/10)-2])+(((no%10)==0)?"":"-"+string(ones[no%10]));
return ab;
}
void main()
{
fstream fin,fout;
fin.open("clock.in",ios::in);
cin=fin;
fout.open("clock.out",ios::out);
string st;
cin >> st;
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();
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.