Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- signed main() {
- freopen("ghiocel.in", "r", stdin);
- freopen("ghiocel.out", "w", stdout);
- function<bool(string)> check[4];
- check[0] = [](string s)->bool {
- return is_sorted(begin(s), end(s), [](char a, char b) {
- return a <= b;
- });
- };
- check[1] = [](string s)->bool {
- return is_sorted(s.rbegin(), s.rend(), [](char a, char b) {
- return a <= b;
- });
- };
- check[2] = [=](string s)->bool {
- unsigned n = s.size();
- if (check[0](s) || check[1](s)) {
- return false;
- }
- unsigned p = 1;
- for (; p < n; p++) {
- if (s[p] < s[p - 1]) {
- break;
- }
- }
- return check[0](s.substr(0, p)) && check[1](s.substr(p));
- };
- check[3] = [=](string s)->bool {
- unsigned n = s.size();
- if (check[0](s) || check[1](s)) {
- return false;
- }
- unsigned p = 1;
- for (; p < n; p++) {
- if (s[p] > s[p - 1]) {
- break;
- }
- }
- return check[1](s.substr(0, p)) && check[0](s.substr(p));
- };
- int n, ans[4] = {};
- cin >> n;
- for (int i = 0; i < n; i++) {
- string s;
- cin >> s;
- for (int j = 0; j < 4; j++) {
- ans[j] += check[j](s);
- }
- }
- for (int i = 0; i < 4; i++) {
- cout << ans[i] << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement