解题思路:
注意事项:
参考代码:
#include<iostream> using namespace std; class Data { public: void Set(string str) { int pos1=0,pos2=0; pos1=str.find("-"); pos2=str.rfind("-"); for(int i=0;i<pos1;i++){ this->year*=10; this->year+=(str[i]-'0'); } for(int i=pos1+1;i<pos2;i++){ this->month*=10; this->month+=(str[i]-'0'); } for(int i=pos2+1;i<str.length();i++){ this->day*=10; this->day+=(str[i]-'0'); } } void print() { cout<<year<<":"<<month<<":"<<day<<endl; } private: int year=0,month=0,day=0; }; int main() { string str; cin>>str; Data D; D.Set(str); D.print(); return 0; }
0.0分
0 人评分