PLAG01 - Editorial

PROBLEM LINK:

PRACTICE
Editorialist: Aditya Verma

DIFFICULTY:

Easy

PREREQUISITES:

String

PROBLEM:

The government has started to make a 1212 digit UID for their respective citizens. This UID will help the govt. to distributing any welfare schemes and many more things. This UID consist of 1212 digits starting with the first digit is ‘9’. But the UID generator has been crashed by some hackers as they have inserted some “Plagiarised Malwares”, which produced some unwanted string ss. Your task is to find whether a given string ss can make it like the original UID as per govt. orders, by deleting some characters from the string.

EXPLANATION:

In this problem, we are given a UID as a string with some variable length. we have to determine whether it is possible for us to convert this number into a ‘12’ digit number starting from ‘9’ by removing any number of characters. So to determine it we can just apply brute force as constraints are not very much large.

SOLUTION:

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

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int len;
        cin >> len;
        string num;
        cin >> num;
        if(num[0] == '9' && len>=12){
            cout << "Possible" << endl;
            continue;
        }
        else if(len < 12){
            cout << "Not Possible" << endl;
        }
        
        else
        {
            
            int position = -1, numbersBefore = 0;
            position = num.find("9");
            if(position!= -1)
            {                                               
                numbersBefore = position;
                
                if(len-numbersBefore >= 12)
                {      
                    cout << "Possible" << endl;                                     
                    continue;
                }
                else
                {                                                       
                    cout << "Not Possible" << endl;
                    continue;
                }
            }
            else
            {                                                             
                cout << "Not Possible" << endl;
                continue;
            }
        }
    }
}