LOCKDOWN - EDITORIAL

Contest Link :
Practice
Contest

Author: Pratik Suryawanshi

Editorialist: Pratik Suryawanshi

DIFFICULTY:

Easy

PREREQUISITES:

String/loops

PROBLEM:

Because of corona there is lockdown outside in chefs city. chef is willing to go outside of
home for some work . but because of lockdown chef will go out if there is safe atmosphere
outside ,otherwise he will not go outside.

The condition for safe atmosphere is number of corona negative patients should be greater
than or equal to number of corona positive patients.

we have given binary number S in which 1 denotes positive patients and 0 denotes negative
patients. [ you can use first line of each test case as a string ]

QUICK EXPLANATION:

Check each number of string, whether it is ‘1’ or ‘0’. if count of 0 is greater than or
equal to 1 print YES , NO otherwise

EXPLANATION:

by applying for loop, from 0 to s.size(). check s[i] == 0 then increment in cnt1,
else increment in cnt2 if cnt1>= cnt2 print YES otherwise NO

SOLUTIONS:

Setter's Solution

indent whole code by 4 spaces

#pragma GCC optimize(“Ofast”)
#pragma GCC target(“avx,avx2,fma”)
#pragma GCC optimization(“unroll-loops”)
#include <bits/stdc++.h>
using namespace std;
#define tc ll t sc cin >> t sc while (t–)
#define ff first
#define vp vector<pair<ll,ll>>
#define sc ;
#define ss second
#define srt sort
#define endl ‘\n’
#define pb push_back
#define pp pop_back
#define mp make_pair
#define modulo 1e9+7
#define ll long long int
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define INF 1001001001
const long double pi = 3.141592653;

typedef unsigned int ui;
typedef unsigned long long int ul;

int main()
{

#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("errorf.txt" , "w" , stderr);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

tc
{
  // code here
    ll a;
    cin >> a;
    ll last_digit;
    int cnt1=0;
    int cnt2=0;
    while(a>0)
    {
         last_digit = a%10;
         
          
   if(last_digit==1)
    {
        cnt1++;
    }
    if(last_digit==0)
    {
        cnt2++;
    }
    
        a /= 10;
        
    }
   
    if(cnt2 >= cnt1)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

}

return 0;
}

Editorialist's Solution

indent whole code by 4 spaces

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

#define google(tc) cout<<“Case #”<<tc++<<": ";
#define FILE freopen(“input.txt”,“r”,stdin); freopen(“output.txt”,“w”, stdout);
#define GetSetBolt ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define LL long long int
#define LD long double

#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define FF first
#define SS second
#define PB push_back
#define PF push_front
#define PPB pop_back
#define PPF pop_front
#define Endl endl

#define in(arr,n) for(int i=0;i<n;i++) cin>>arr[i];
#define in2(arr,n,m) for(int i=0;i<n;i++){ for(int j=0;j<m;j++) cin>>arr[i][j];}
#define dis(arr,n) for(int i=0;i<n;i++) cout<<arr[i]<<" “; cout<<endl;
#define dis2(arr,n,m) for(int ii=0;ii<n;ii++){for(int j=0;j<m;j++)cout<<arr[ii][j]<<” ";cout<<endl;}
#define TC() int t=0;cin>>t; while(t–)

#define For(n) for(LL i=0;i<n;i++)
#define For0(x,z) for(LL x=0;x<z;x++)
#define Forx(x,z) for(x;x<z;x++)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()

#define toLower(s) transform(s.begin(),s.end(),s.begin(),::tolower)
#define toUpperr(s) transform(s.begin(),s.end(),s.begin(),::toupper)

#define sortAD(arr,n) sort(arr,arr+n, greater());
#define sortVD(v) sort(v.begin(), v.end(), greater());
#define sortA(arr) sort(arr,arr+n);
#define sortV(v) sort(v.begin(),v.end());

#define mem0(X) memset((X), 0, sizeof((X)))
#define memx(X,x) memset((X), x, sizeof((X)))
#define setbits(X) __builtin_popcountll(X)
#define precise(X) cout<<fixed << setprecision(X);

// #ifndef ONLINE_JUDGE
// cerr<<"\ntime taken : “<<(float)clock()/CLOCKS_PER_SEC<<” secs"<<"\n";
// #endif
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<double,double> PDD;
typedef pair<string, string> PSS;
typedef pair<string, LL> PSL;

typedef vector VI;
typedef vector VL;
typedef vector VD;
typedef vector VS;
typedef vector VVI;
typedef vector VVL;
typedef vector VVS;
typedef vector VPII;
typedef vector VPLL;
typedef vector VPSS;
typedef vector VPSL;

typedef map<int,int> MII;
typedef map<LL,LL> MLL;
typedef map<char,LL> MCL;
typedef map<char,int> MCI;
typedef map<char,LL> MCL;
typedef map<string,string> MSS;
typedef map<string,int> MSI;
typedef map<string,LL> MSL;

typedef unordered_map<int,int> UMII;
typedef unordered_map<LL,LL> UMLL;
typedef unordered_map<char,LL> UMCL;
typedef unordered_map<char,int> UMCI;
typedef unordered_map<char,LL> UMCL;
typedef unordered_map<string,string> UMSS;
typedef unordered_map<string,int> UMSI;
typedef unordered_map<string,LL> UMSL;

LL lcm(LL a, LL b)
{ return (a * (b / __gcd(a, b))); }

string intToString(LL a)
{
char x[100];
sprintf(x, “%lld”, a);
string s = x;
return s;
}

LL stringToInt(string a)
{
char x[100];
LL res;
strcpy(x, a.c_str());
sscanf(x, “%lld”, &res);
return res;
}

bool isPrime(int n)
{
if (n <= 1)
return false;
for (int i = 2; i <= sqrt(n); i++)
if (n % i == 0)
return false;
return true;
}

string to_binary(LL n)
{
int bin[100];
int i = 0;
while (n > 0) {
bin[i] = n % 2;
n = n / 2;
i++;
}
string s="";
for(int j=i-1;j>=0;j–)
s+=to_string(bin[j]);
return s;
}

int main()
{
// code here
int t;
cin >> t;
while(t–)
{
string s;
cin >> s;
int cnt1=0,cnt0=0;
for(int i=0;i<s.size();i++)
{
if(s[i]== ‘0’)
{
cnt0++;
}
else
{
cnt1++;
}
}
if(cnt0 >= cnt1)
{
cout << “Yes” << “\n”;
}
else
cout << “No” << “\n”;
}

return 0;

}