Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ull unsigned long long
- using namespace std;
- struct elem
- {
- string date;
- ull val;
- ull dd, mm, yy;
- };
- bool byYyMmDd(const elem &lhs, const elem &rhs)
- {
- if(lhs.yy != rhs.yy) {
- return lhs.yy < rhs.yy;
- }
- if(lhs.mm != rhs.mm) {
- return lhs.mm < rhs.mm;
- }
- if(lhs.dd != rhs.dd) {
- return lhs.dd < rhs.dd;
- }
- }
- int main()
- {
- vector<elem> vec;
- string s;
- ull val;
- while (cin >> s >> val)
- {
- vec.push_back({s, val});
- }
- ull dd, mm, yy;
- for(auto &x : vec) {
- string s = x.date;
- int pr = 0;
- vector<int> vals;
- for(int i = 0; i < s.size(); i++) {
- if(s[i] == '.') {
- vals.push_back(atoi(s.substr(pr, i - pr).c_str()));
- pr = i + 1;
- }
- // 1.1.1
- }
- vals.push_back(atoi(s.substr(pr).c_str()));
- x.dd = vals[0], x.mm = vals[1], x.yy = vals[2];
- }
- sort(vec.begin(), vec.end(), byYyMmDd);
- for(auto &x : vec) {
- cout << x.date << " " << x.val << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement