AFAIK一个世纪在所有语言环境中均定义为100年。但是,还有一个世纪开始的问题。(您是从零开始还是从一个开始计数?)假设使用公历或与教皇格雷格有关何时开始计数的日历:
#include <iostream>
int yearToCentury(int year)
{
return (year + 99) / 100;
}
int main()
{
std::cout << 1999 << ": " << yearToCentury(1999) << std::endl;
std::cout << 2000 << ": " << yearToCentury(2000) << std::endl;
std::cout << 2001 << ": " << yearToCentury(2001) << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
产生以下结果:
1999: 20
2000: 20
2001: 21
Run Code Online (Sandbox Code Playgroud)
但是,我找不到标准库中或函数提升为您进行此计算的证据。