首页 > 解决方案 > 从 2 位输入输出 4 位年份

问题描述

这是我正在编写的代码的一部分。

如果 à 用户以 2 位数字输入年份 ( '94 ),则它将年份输出为 4 位数字 { 1994 )

我遇到了需要与我需要相反的问题:将 4 位数年份转换为 2 位数年份

我的部分代码:

#include <iostream>
using namespace std;

int main() {
     Int yr;

    cout<<"Enter year: " <<endl;
    cin>>yr;

    cout<<"The year is "<<yr<<endl;

    return 0;
  } 

标签: c++inputoutput

解决方案


当人们在 1990 年代后期进行 y2k 转换时,这种情况经常出现。

一种常见的实现是选择 1950 作为截止值,因此51through99被视为1951through 1999,而00through50被视为2000through 2050


推荐阅读