hackerrank The Time in Words

来源:互联网 发布:白苹果保留数据刷机 编辑:程序博客网 时间:2024/05/24 01:16

这里写图片描述

#include<stdio.h>#include<iostream>#include<string.h>#include<math.h>#include<algorithm>#include<queue>#include<set>#include<iterator>#include<map>using namespace std;int main(){    string time[31] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight",                  "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "quarter",                    "sixteen", "seventeen", "eighteen", "nineteen", "twenty", "twenty one",                   "twenty two", "twenty three", "twenty four", "twenty five", "twenty six",                   "twenty seven", "twenty eight", "twenty nine", "half"};    //while(1){    int H, M;    scanf("%d%d", &H, &M);    if(M == 0){        cout << time[H] << " o' clock" << endl;    }else if(M > 30){        H += 1; M = 60 - M;        if(H == 24) H = 0;        if(M == 1){            cout << time[M] << " minute to " << time[H] << endl;        }else if(M == 15){            cout << time[M] << " to " << time[H] << endl;        }else{            cout << time[M] << " minutes to " << time[H] << endl;        }       }else{        if(M == 1){            cout << time[M] << " minute past " << time[H] << endl;        }else if(M == 15 || M == 30){            cout << time[M] << " past " << time[H] << endl;        }else{            cout << time[M] << " minutes past " << time[H] << endl;        }       }               //}     return 0;}