首页IT科技roman numeral什么意思(Roman numerals/Encode Rosetta Code)

roman numeral什么意思(Roman numerals/Encode Rosetta Code)

时间2025-05-01 18:43:03分类IT科技浏览4347
导读:C++ #include...

C++

#include <iostream> #include <string> std::string to_roman(int value) { struct romandata_t { int value; char const* numeral; }; static romandata_t const romandata[] = { 1000, "M", 900, "CM", 500, "D", 400, "CD", 100, "C", 90, "XC", 50, "L", 40, "XL", 10, "X", 9, "IX", 5, "V", 4, "IV", 1, "I", 0, NULL }; // end marker std::string result; for (romandata_t const* current = romandata; current->value > 0; ++current) { while (value >= current->value) { result += current->numeral; value -= current->value; } } return result; } int main() { for (int i = 1; i <= 4000; ++i) { std::cout << to_roman(i) << std::endl; } }

创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

展开全文READ MORE
模型训练三要素(模型训练步骤) phpcms怎么用(PHPCMS 登录界面能自己换吗?)