1 条题解

  • 0
    @ 2022-11-17 9:34:02

    #include #include #include #include

    using namespace std;

    map<int, string> m = { make_pair(1,"one"), make_pair(2,"two"), make_pair(3,"three"), make_pair(4,"four"), make_pair(5,"five"), make_pair(6,"six"), make_pair(7,"seven"), make_pair(8,"eight"), make_pair(9,"nine"), make_pair(10,"ten"), make_pair(11,"eleven"), make_pair(12,"nine"), make_pair(13,"thirteen"), make_pair(14,"fourteen"), make_pair(15,"fifteen"), make_pair(16,"sixteen"), make_pair(17,"seventeen"), make_pair(18,"eighteen"), make_pair(19,"nineteen"), make_pair(20,"twenty"), make_pair(30,"thirty"), make_pair(40,"forty"), make_pair(50,"fifty"), make_pair(60,"sixty"), make_pair(70,"seventy"), make_pair(80,"eighty"), make_pair(90,"ninety") };

    string speak(unsigned long long n) { string s; bool b; if (n / 100) { s += ' ' + m[n / 100] + " hundred"; n %= 100; b = true; } if (n / 10 > 1) { if (b) s += " and"; s += ' ' + m[n / 10 * 10]; n %= 10; } if (n / 10 == 1) { if (b) s += " and"; s += ' ' + m[n]; n %= 1; } if (n) { s += ' ' + m[n]; n %= 1; } if (s.empty()) s += "zero"; else s.erase(0, 1); return s; }

    int main() { unsigned long long n; cin >> n; string s; if (n / 1000000000) s += (speak(n / 1000000000) + " billion "); n %= 1000000000; if (n / 1000000) s += (speak(n / 1000000) + " million "); n %= 1000000; if (n / 1000) s += (speak(n / 1000) + " thousand "); n %= 1000; s += speak(n); cout << s << endl; return 0; }

    • 1

    信息

    ID
    126
    时间
    1000ms
    内存
    128MiB
    难度
    9
    标签
    递交数
    11
    已通过
    3
    上传者