返回题解分享
讨论 / 题解分享/ 帖子详情

日期问题(编程题) - 题解

#include <bits/stdc++.h>
using namespace std;

int main()
{
string date;
getline(cin, date);
string fr=date.substr(0, 2);
string sc=date.substr(3, 2);
string td=date.substr(6, 2);
set<string> s_st;          //集合
string ymd, mdy, dmy;
if(sc!="00" && td!="00")   //没有00月00日
ymd="20"+fr+"-"+sc+"-"+td;
if(fr!="00" && sc!="00")
mdy="20"+td+"-"+fr+"-"+sc;
if(sc!="00" && fr!="00")
dmy="20"+td+"-"+sc+"-"+fr;
s_st.insert(ymd);
s_st.insert(mdy);
s_st.insert(dmy);
s_st.erase("");           //如果insert了00月或00日
for(auto &ele : s_st)
cout << ele << endl;
return 0;
}
0 回复 0 转发 0 喜欢 3 阅读
回复 (0)
默认 最新
暂无回复,快来抢沙发!