Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream> // std::cout
- #include <algorithm> // std::sort
- #include <vector> // std::vector
- int getYear(int date) {
- int year = (date / 10000);
- return (year < 20) ? 2000+year : year;
- }
- int getMonth(int date) {
- int month = (date / 100) % 100;
- return (date /100) % 100;
- }
- int getDay(int date) {
- int d2 = (date /10) % 10;
- int d1 = (date /100) % 10;
- return d2*10+d1;
- }
- bool myfunction (int i,int j) {
- if (getYear(i) > getYear(j)) return true;
- if (getYear(i) == getYear(j) && getMonth(i) > getMonth(j)) return true;
- if (getYear(i) == getYear(j) && getMonth(i) == getMonth(j) && getDay(i) > getDay(j)) return true;
- return false;
- }
- int main () {
- int myints[] = {130525,951022 , 130624, 121212};
- std::vector<int> myvector (myints, myints+4); // 32 71 12 45 26 80 53 33
- std::sort (myvector.begin(), myvector.end(), myfunction); // 12 32 45 71(26 33 53 80)
- std::cout << "Year: " << getYear(130525);
- std::cout << "Month:" << getMonth(130525);
- std::cout << "Day:" << getDay(130525);
- std::cout << std::endl <<std::endl;
- std::cout << "Year: " << getYear(951022);
- std::cout << "Month:" << getMonth(951022);
- std::cout << "Day:" << getDay(951022);
- std::cout << std::endl;
- std::cout << "myvector contains:";
- for (std::vector<int>::iterator it=myvector.begin(); it!=myvector.end(); ++it)
- std::cout << ' ' << *it;
- std::cout << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement