Get me outta here!

Thursday, May 26, 2022

Calculate easy way (My created easy problem- Codeforces Style)

 

Solution

#include<iostream>

using namespace std;

int main()

{

    int n,p;

    cin>>n>>p;

    if(n>p)

    {

        while(n%10!=0)

        {

            n++;

            p--;

        }

        cout<<n<<" "<<p;

    }

    else if(p>n)

    {

        while(p%10!=0)

        {

            p++;

            n--;

        }

        cout<<n<<" "<<p;

    }

}


Thursday, May 19, 2022

How to reverse a string (with Codeforces Example)

 

The algorithm will first have to reverse the string and check with the second string. We can do this both in library function and also by using a loop.


So the solution of first image is given below:

#include<bits/stdc++.h>

#include<string>

using namespace std;

int main()

{

    string s,t;

    cin>>s>>t;

    string rev1="";

    //reverse(s.begin(),s.end()); //Library function 

    //using loop

    for (int i = s.size() - 1; i >= 0; i--)

    {

        rev1 = rev1 + s[i];

    }

    if(rev1==t)

        cout<<"YES";

    else

        cout<<"NO";

}


Sunday, April 24, 2022

DlC Latch










Saturday, April 16, 2022

First and follow Rules (Compiler)

First Set

1st Rule: if terminal, then insert terminal on set

2nd Rule: if ∈, then insert ∈ on set

3rd Rule: if non-terminal, then check the productions and insert the production elements.

-----------------------------------------------------------------------

Follow Set

1st Rule: For start variable, input $

2nd Rule: if A → αBβ, then follow(B) = first(β)

3rd Rule: if A → αB, then follow(B)= follow(A)