906A - Shockers - CodeForces Solution


implementation strings *1600

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<bool> x(26, 1);
  int t = 26, r = 0;
  for (int i = 0; i < n; i++) {
    string s;
    char a;
    cin >> a;
    if (a == '.') {
      cin >> s;
      for (char c : s)
        if (x[c-'a'])
          x[c-'a'] = 0, t--;
    } else if (a == '!') {
      cin >> s;
      if (t == 1) {
        r++;
        continue;
      }
      vector<bool> y(26);
      for (char c : s) y[c-'a'] = 1;
      for (int i = 0; i < 26; i++)
        if (!y[i] && x[i])
          x[i] = 0, t--;
    } else {
      cin >> a;
      if (t == 1 && !x[a-'a']) r++;
      else if (x[a-'a']) x[a-'a'] = 0, t--;
    }
  }
  cout << r << '\n';
}


Comments

Submit
0 Comments
More Questions

1041D - Glider
1486A - Shifting Stacks
1389B - Array Walk
71B - Progress Bar
701A - Cards
545A - Toy Cars
1538E - Funny Substrings
234A - Lefthanders and Righthanders
1611D - Weights Assignment For Tree Edges
197A - Plate Game
1474A - Puzzle From the Future
6B - President's Office
1405B - Array Cancellation
431C - k-Tree
101A - Homework
1642C - Great Sequence
1523B - Lord of the Values
1406C - Link Cut Centroids
2409. Count Days Spent Together
2410. Maximum Matching of Players With Trainers
1604C - Di-visible Confusion
997A - Convert to Ones
218A - Mountain Scenery
486B - OR in Matrix
1405A - Permutation Forgery
1733A - Consecutive Sum
1733B - Rule of League
1733C - Parity Shuffle Sorting
1264A - Beautiful Regional Contest
1695A - Subrectangle Guess