티스토리 뷰

출처 : https://www.hackerrank.com/challenges/the-time-in-words/problem


#include <bits/stdc++.h>


using namespace std;


string minutes[30] = { "one minute",

"two minutes",

"three minutes",

"four minutes",

"five minutes",

"six minutes",

"seven minutes",

"eight minutes",

"nine minutes",

"ten minutes",

"eleven minutes",

"twelve minutes",

"thirteen minutes",

"forteen minutes",

"quarter",

"sixteen minutes",

"seventeen minutes",

"eighteen minutes",

"nineteen minutes",

"twenty minutes",

"twenty one minutes",

"twenty two minutes",

"twenty three minutes",

"twenty four minutes",

"twenty five minutes",

"twenty six minutes",

"twenty seven minutes",

"twenty eight minutes",

"twenty nine minutes",

"half" };

string hours[12] = { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve" };


string timeInWords(int h, int m) {

if (m == 0) return hours[h - 1] + " o' clock";

else if (m <= 30) return minutes[m - 1] + " past " + hours[h - 1];

else return minutes[60 - m - 1] + " to " + hours[h];

}


int main()

{

ofstream fout(getenv("OUTPUT_PATH"));


int h;

cin >> h;

cin.ignore(numeric_limits<streamsize>::max(), '\n');


int m;

cin >> m;

cin.ignore(numeric_limits<streamsize>::max(), '\n');


string result = timeInWords(h, m);


fout << result << "\n";


fout.close();


return 0;

}



'알고리즘 > 기타' 카테고리의 다른 글

[HackerRank] Lily's Homework  (0) 2018.10.02
[HackerRank] The Grid Search  (0) 2018.10.01
[HackerRank] Bigger is Greater  (0) 2018.10.01
[HackerRank] Organizing Containers of Balls  (0) 2018.10.01
[HackerRank] Queen's Attack II  (0) 2018.09.30
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
글 보관함