260B - Ancient Prophesy - CodeForces Solution


brute force implementation strings *1600

Please click on ads to support us..

C++ Code:

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;

#define ll long long

ll gcd(ll a, ll b) { return ((b == 0) ? a : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return (b / gcd(a, b)) * a; }

void Candidate_Elde7k() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
}

bool validDay(string x, int month) {
    if (x.size() != 2) return false;
    int day = stoi(x);
    if (month == 1 || month == 3 || month == 5 || month == 7 ||
        month == 8 || month == 10 || month == 12) return (day >= 1 && day <= 31);
    else if (month == 2) return (day >= 1 && day <= 28);
    else return (day >= 1 && day <= 30);
}
bool validMonth(string x) {
    if (x.size() != 2) return false;
    int y = stoi(x);
    return (y >= 1 && y <= 12);
}
bool validYear(string x) {
    if (x.size() != 4) return false;
    int y = stoi(x);
    return (y >= 2013 && y <= 2015);
}

int main() {
    Candidate_Elde7k();
    string s; cin >> s;
    int n = s.size();
    map<string, int>save;
    for (int i = 0; i + 9 < n; i++) {
        if (s[i] != '-') {
            bool flag = true;
            string day = "";
            string month = "";
            string year = "";
            int j = i;
            while (j < i + 2) {
                flag &= (s[j] != '-');
                day += s[j++];
            }
            flag &= (s[j] == '-');
            j++;
            while (j < i + 5) {
                flag &= (s[j] != '-');
                month += s[j++];
            }
            flag &= (s[j] == '-');
            j++;
            while (j < i + 10) {
                flag &= (s[j] != '-');
                year += s[j++];
            }
            if (flag) {
                if (validMonth(month) && validYear(year) && validDay(day, stoi(month))) {
                    string t = day + "-" + month + "-" + year;
                    save[t]++;
                }
            }
        }
    }
    string ans = "";
    int mx = 0;
    for (auto& it : save) {
        if (it.second > mx) {
            mx = it.second;
            ans = it.first;
        }
    }
    cout << ans << "\n";
}


Comments

Submit
0 Comments
More Questions

577A - Multiplication Table
817C - Really Big Numbers
1355A - Sequence with Digits
977B - Two-gram
993A - Two Squares
1659D - Reverse Sort Sum
1659A - Red Versus Blue
1659B - Bit Flipping
1480B - The Great Hero
1519B - The Cake Is a Lie
1659C - Line Empire
515A - Drazil and Date
1084B - Kvass and the Fair Nut
1101A - Minimum Integer
985D - Sand Fortress
1279A - New Year Garland
1279B - Verse For Santa
202A - LLPS
978A - Remove Duplicates
1304A - Two Rabbits
225A - Dice Tower
1660D - Maximum Product Strikes Back
1513A - Array and Peaks
1251B - Binary Palindromes
768B - Code For 1
363B - Fence
991B - Getting an A
246A - Buggy Sorting
884A - Book Reading
1180A - Alex and a Rhombus