Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <algorithm>
- #include <sstream>
- //#include <ctime>
- #pragma GCC optimize ("O2")
- using namespace std;
- int main()
- {
- tm first, second;
- string BEGIN;
- cin >> BEGIN; cin.ignore();
- string END;
- cin >> END; cin.ignore();
- long int day,month,year,day1,month1,year1;
- replace( BEGIN.begin(),BEGIN.end(),'.',' ');
- istringstream( BEGIN ) >> first.tm_mday >> first.tm_mon >> first.tm_year;
- replace( END.begin(),END.end(),'.',' ');
- istringstream( END ) >> second.tm_mday >> second.tm_mon >> second.tm_year;
- first.tm_mon--;
- second.tm_mon--;
- first.tm_year -= 1900;
- second.tm_year -= 1900;
- first.tm_hour = first.tm_min = first.tm_sec = 0;
- second.tm_hour = second.tm_min = second.tm_sec = 0;
- long int difference = difftime(mktime(&second), mktime(&first));//16 years, total 5844 days
- long int dayt = difference / (60*60*24);
- difference = second.tm_year - first.tm_year;
- long int monn = second.tm_mon - first.tm_mon;
- if (second.tm_mon < first.tm_mon) {
- difference=difference-1;monn=monn+12;
- }
- if(second.tm_mday < first.tm_mday){
- monn=monn-1;
- }
- if(monn==0 && difference== 0){
- cout << "total "<<dayt <<" days"<< endl;
- }
- else if(monn==0 && difference !=1){
- cout << difference <<" years, total "<< dayt <<" days"<< endl;//16 years, total 5844 days
- }
- else if(monn==0 && difference ==1){
- cout << difference <<" year, total "<< dayt <<" days"<< endl;//16 years, total 5844 days
- }
- else if (difference== 0 && monn!=1){
- cout << monn<<" months, total "<< dayt <<" days"<< endl;
- }
- else if (difference== 0 && monn==1){
- cout << monn<<" month, total "<< dayt <<" days"<< endl;
- }
- if (difference != 0 && monn!=0 && dayt != 0 && monn!=1 && difference != 1)
- cout << difference << " years, "<< monn<<" months, total "<< dayt <<" days"<< endl;
- else if (difference != 0 && monn!=0 && dayt != 0 && monn==1 && difference == 1)
- cout << difference << " year, "<< monn<<" month, total "<< dayt <<" days"<< endl;
- else if (difference != 0 && monn!=0 && dayt != 0 && difference == 1)
- cout << difference << " year, "<< monn<<" months, total "<< dayt <<" days"<< endl;
- else if (difference != 0 && monn!=0 && dayt != 0 && monn == 1)
- cout << difference << " years, "<< monn<<" month, total "<< dayt <<" days"<< endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement