Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
- // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx")
- #include <iostream>
- #include <vector>
- #include <cmath>
- #include <algorithm>
- #include <unordered_map>
- #include <set>
- #include <map>
- #include <queue>
- #include <random>
- #include <chrono>
- #include <cassert>
- #include <sstream>
- #include <fstream>
- #include <iomanip>
- #define fi first
- #define se second
- #define pb push_back
- #define ll long long
- #define ld long double
- #define hm unordered_map
- #define pii pair<int, int>
- #define sz(a) (int)a.size()
- #define all(a) a.begin(), a.end()
- #define cinv(v) for (auto& x: v) cin >> x
- #define fr(i, n) for (int i = 0; i < n; ++i)
- #define fl(i, l, n) for (int i = l; i < n; ++i)
- // #define int ll
- template <typename T1, typename T2> inline bool chkmin(T1 &x, const T2 &y) {if (x > y) {x = y; return 1;} return 0;}
- template <typename T1, typename T2> inline bool chkmax(T1 &x, const T2 &y) {if (x < y) {x = y; return 1;} return 0;}
- using namespace std;
- #ifdef LOCAL
- #define dbg(x) cerr << #x << " : " << x << '\n'
- #else
- #define dbg(x)
- #endif
- //tg: @runningcherry
- template <typename T1, typename T2> ostream& operator << (ostream& out, const pair<T1, T2>& v) {
- out << v.fi << ", " << v.se;
- return out;
- }
- template<typename T> ostream& operator << (ostream& out, const vector<T>& v) {
- for (auto& x: v) out << x << " ";
- return out;
- }
- template <typename T1, typename T2> ostream& operator << (ostream& out, const map<T1, T2>& v) {
- for (auto& x: v) out << x << '\n';
- return out;
- }
- template<typename T> ostream& operator << (ostream& out, const set<T>& v) {
- for (auto& x: v) out << x << " ";
- return out;
- }
- template<typename T> ostream& operator << (ostream& out, const multiset<T>& v) {
- for (auto& x: v) out << x << " ";
- return out;
- }
- template <typename T1, typename T2> istream& operator >> (istream& in, pair<T1, T2>& a) {
- in >> a.fi >> a.se;
- return in;
- }
- const ll inf = (ll) 2e9;
- const ld pi = asin (1) * 2;
- const ld eps = 1e-8;
- const ll mod = (ll)1e9 + 7;
- const ll ns = 97;
- const int maxn = 2e5 + 20;
- mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
- struct Date {
- int year, month, day;
- inline bool operator < (const Date& other) const {
- if (year == other.year) {
- if (month == other.month) {
- return day < other.day;
- }
- return month < other.month;
- }
- return year < other.year;
- }
- };
- ostream& operator<< (ostream& out, const Date& date) {
- out << setw (4) << setfill ('0') << date.year << '-' <<
- setw (2) << setfill ('0') << date.month << '-' <<
- setw (2) << setfill ('0') << date.day;
- return out;
- }
- map <Date, set<string>> kek;
- void check_next_char (istream& stream, const string& date) {
- if (stream.peek () != '-') {
- throw runtime_error ("Wrong date format: " + date);
- }
- stream.ignore (1);
- }
- Date get_date (istream& stream) {
- string date;
- stream >> date;
- if (!stream) throw runtime_error ("Wrong date format: " + date);
- stringstream in (date);
- int year, month, day;
- in >> year;
- check_next_char (in, date);
- in >> month;
- check_next_char (in, date);
- in >> day;
- if (!in) throw runtime_error ("Wrong date format: " + date);
- char x;
- in >> x;
- if (in) throw runtime_error ("Wrong date format: " + date);
- if (month < 1 || 12 < month) throw runtime_error ("Month value is invalid: " + to_string (month));
- if (day < 1 || 31 < day) throw runtime_error ("Day value is invalid: " + to_string (day));
- return {year, month, day};
- }
- void read () {
- string line;
- if (!getline (cin, line)) exit (0);
- if (line.empty ()) return;
- stringstream stream (line);
- string command;
- stream >> command;
- if (command == "Add") {
- auto date = get_date (stream);
- string event;
- stream >> event;
- kek[date].insert (event);
- } else if (command == "Del") {
- auto date = get_date (stream);
- string event;
- stream >> event;
- if (!stream) {
- int n = sz (kek[date]);
- cout << "Deleted " << n << " events\n";
- kek.erase (date);
- } else {
- if (kek[date].count (event)) {
- cout << "Deleted successfully\n";
- } else {
- cout << "Event not found\n";
- }
- kek[date].erase (event);
- }
- } else if (command == "Find") {
- auto date = get_date (stream);
- for (const auto& s: kek[date]) cout << s << '\n';
- } else if (command == "Print") {
- for (const auto& ptt: kek) {
- for (const auto& s: ptt.se) {
- cout << ptt.fi << ' ' << s << '\n';
- }
- }
- } else {
- throw runtime_error ("Unknown command: " + command);
- }
- }
- signed main () {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- while (1) {
- try {
- read ();
- } catch (exception& ex) {
- cout << ex.what () << '\n';
- }
- }
- }
Add Comment
Please, Sign In to add comment