We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Hello
What is wrong in my code ?
I have 2 uses cases which fail (7 + 29 and 6 + 35) while the output seems correct to me...
stringnum2word(intn){strings;intt=n/10;intu=n%10;switch(t){case0:if(u==0)return"zero";break;case1:switch(u){case0:s="ten";break;case1:s="eleven";break;case2:s="twelve";break;case3:s="thirteen";break;case4:s="fourteen";break;case5:s="quarter";break;case6:s="sixteen";break;case7:s="seventeen";break;case8:s="eighteen";break;case9:s="nineteen";break;}returns;break;case2:s="tweenty";break;}switch(u){case1:s+=" one";break;case2:s+=" two";break;case3:s+=" three";break;case4:s+=" four";break;case5:s+=" five";break;case6:s+=" six";break;case7:s+=" seven";break;case8:s+=" eight";break;case9:s+=" nine";break;}returnltrim(s);}stringtimeInWords(inth,intm){strings;if(h==0&&m==0)return"midnight";if(h==12&&m==0)return"noon";if(m==30)return"half past "+num2word(h);if(m==15)return"quarter past "+num2word(h);if(m==45)return"quarter to "+num2word(h+1);if(m==0)returnnum2word(h)+" o' clock";switch(m){case1:s=" minute";break;default:s=" minutes";break;}if(m>30)returnnum2word(60-m)+s+" to "+num2word(h+1);returnnum2word(m)+s+" past "+num2word(h);}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
The Time in Words
You are viewing a single comment's thread. Return to all comments →
Hello What is wrong in my code ? I have 2 uses cases which fail (7 + 29 and 6 + 35) while the output seems correct to me...