Manasa loves Maths Hackerrank
Solution:
#include<bits/stdc++.h> using namespace std ; typedef long long ll; typedef pair<ll, ll> Pll; #define F first #define S second #define MP make_pair #define PB push_back #define rad(X) cout << (X) << endl #define ASH(X) cout << (X) << " " #define debug(x) cout << #x << " " << x << endl; #define debug2(x,y) cout << #x << " " << x << " " << #y << " " << y << endl; #define FOR(I,A,B) for(ll I = (A); I <= (B); I++) #define cir(I,B,A) for(ll I = (A); I >=(B); I--) #define MS0(X) memset((X), 0, sizeof((X))) #define MS1(X) memset((X), -1, sizeof((X))) #define SORT(c) (sort(c.begin(),c.end())) #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin()) #define CASES int ___T; cin >> ___T; for(int cs=1;cs<=___T;cs++) #define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); ll fx[] = {1, 1, 0, -1, -1, -1, 0, 1}; ll fy[] = {0, 1, 1, 1, 0, -1, -1, -1}; vector<ll>a,b,c; map<ll,ll>m1,m2,m3; /************************************************/ void Execute() { ll n, nb, k, q, a, b, c, l, r, d, x, y, p, m; string s; cin >> s; l = s.size(); vector<ll>per; FOR(i,0,l-1) { d = s[i]-'0'; per.PB(d); } //SORT_UNIQUE(per); if(per.size()==1) { if(per[0]%8==0) rad("YES"); else rad("NO"); } else if(per.size()<3) { ll prothom_dig = per[0]; ll ditio_dig = per[1]; ll res1 = (prothom_dig*10) + ditio_dig; ll res2 = (ditio_dig*10) + prothom_dig; if(res1%8 == 0 || res2%8 == 0) rad("YES"); else rad("NO"); } else { bool ok = false; FOR(i,0,per.size()-1) { FOR(j,0,per.size()-1) { FOR(k,0,per.size()-1) { if(i!=j && j!=k && k!=i) { ll ans = (per[i]*10) + per[j]; ans = (ans*10)+per[k]; //debug(ans); if(ans%8 == 0) { ok = true; break; } } } if(ok == true ) break; } if(ok == true ) break; } if(ok == true) rad("YES"); else rad("NO"); } } int32_t main() { FAST(); CASES { Execute(); } }
Comments
Post a Comment