Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bits/stdc++.h"
- using namespace std;
- #define nl "\n"
- #define ll long long
- #define mod 1'000'000'007
- #define all(v) v.begin(), v.end()
- #define rall(v) v.rbegin(), v.rend()
- #define sz(v) (int) v.size()
- template<typename T = int>
- istream &operator>>(istream &in, vector<T> &v) {
- for (auto &x: v) in >> x;
- return in;
- }
- template<typename T = int>
- ostream &operator<<(ostream &out, const vector<T> &v) {
- for (const T &x: v) out << x << " ";
- return out;
- }
- void Sira() {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- void check(string s) {
- int cntOp = 0, cntDig = 0 , cntZero = 0 , cntDiv = 0;
- bool neg = false;
- for (int i = 0; i < sz(s); i++) {
- if (s[i] == '*' || s[i] == '/' || s[i] == '+' || s[i] == '-') {
- cntOp++;
- if (s[i] == '/') cntDiv++;
- if (s[i] == '-') neg = true;
- } else {
- cntDig++;
- if (s[i] == '0') cntZero++;
- }
- }
- if (cntDig - cntOp == 1) {
- int cntPos = cntDig - cntZero;
- if (cntPos >= cntDiv) cout << "Valid" << nl;
- else cout << "Invalid" << nl;
- } else if (cntDig == cntOp) {
- int cntPos = cntDig - cntZero;
- if (neg) cntPos--;
- if (cntPos >= cntDiv and neg) cout << "Valid" << nl;
- else cout << "Invalid" << nl;
- }else {
- cout << "Invalid" << nl;
- }
- }
- void solve() {
- string s;
- cin >> s;
- check(s);
- }
- int main() {
- Sira();
- int t = 1;
- cin >> t;
- while (t--) {
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement