Please Install our Kuizzer app ! ---- Doesn't Know how to install click here!

Codechef Practice | Week 5

CODECHEF SOLUTION

Week 5 link: Chandigarh University Week 5 Coding Competition | CodeChef

1. Lapindromes: LAPIN

link: https://www.codechef.com/CUCSE2PP0005/problems/LAPIN

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

int main() {
    int t;
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        string first, second;
        int n = s.length();
        for(int i=0;i<n/2;i++)
        {
            first+=s[i];
            second+=s[n-i-1];
        }
        sort(first.begin(), first.end());
        sort(second.begin(), second.end());
        
        if(first == second)
        {
            cout<<"YES\n";
        }
        else
        {
            cout<<"NO\n";
        }
    }
}

2. Mathison and pangrams: MATPAN

link: https://www.codechef.com/CUCSE2PP0005/problems/MATPAN

#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int t;
    cin >> t;
    while (t--) {
        char x = 'a';
        vector<char> alpha;
        vector<int> cost(26);
        for (int i = 1; i <= 25; i++) {
            alpha.push_back(x);
            x = x + 1;
        }
        alpha.push_back(x);
        //-----------------------------------
        for (int i = 0; i < 26; i++)
            cin >> cost[i];
        string s;
        cin >> s;
        for (int i = 0; i < s.length(); i++) {
            for (int j = 0; j < 26; j++)
                if (s[i] == alpha[j] && alpha[j] != '0')
                    alpha[j] = '0';
        }
        int sum = 0;
        for (int i = 0; i < 26; i++) {
            if (alpha[i] != '0')
                sum += cost[i];
        }
        cout << sum << endl;
    }

    return 0;
}

3. Chef and Subarray: CHEFZOT


link: https://www.codechef.com/CUCSE2PP0005/problems/CHEFZOT

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	int n; cin>>n;
	int count = 0, m=0;
	vector<int> v;
	while(n--){
	    int x; 
	    cin>>x;
	    if(x==0){
	        count = 0;
	        }
	    else {
	        count++;
	        m = max(m, count);
	    }
	}
	cout<<m<<endl;
	return 0;
}


4. Playing with Strings: PLAYSTR

link: https://www.codechef.com/CUCSE2PP0005/problems/PLAYSTR

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{   int n;
	   cin>>n;
	   int z=0,x=0;
	    string s;
	    string st;
	    cin>>s>>st;
	    for(int i=0;i<n;i++)
	    {
	        if(s[i]=='1')
	        z++;
	        if(st[i]=='1')
	        x++;
	    }
	   
	    if(z==x)
	    cout<<"YES"<<endl;
	    else
	    cout<<"NO"<<endl;
	
	}
	return 0;
}




5. Testing Robot: TSTROBOT

link: https://www.codechef.com/CUCSE2PP0005/problems/TSTROBOT

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

int main() {
    int t;
    cin>>t;
    while (t--){
        int  n,x;
        cin>>n>>x;
        string s;
        cin>>s;
        set<int>s1;
        s1.insert(x);
        for(int i=0;i<n;i++){
            if(s[i]=='R'){
                x+=1;
                s1.insert(x);
            }
            else{
                x-=1;
                s1.insert(x);
        }
    }
    cout<<s1.size()<<endl;
	// your code goes here
}
	return 0;
}

* The material and content uploaded on this website are for general information and reference purposes only and don’t copy the answers of this website to any other domain without any permission or else copyright abuse will be in action.

Please do it by your own first!

DMCA.com Protection Status

5 1 vote
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
KUIZZER Helping Educational website for Youngers

Welcome To Kuizzer!

KUIZZER - Helping Educational Website for YoungersYour Post is going to visible like this

Here, Your Promotional Details are going to visible for others whenever they visit the site !

AdBlock Detected

Looks like you are using an ad-blocking browser extension. We request you to whitelist our website on the ad-blocking extension and refresh your browser to view the content.

Check out our merchandise, available at kuizzer.in

X
0
Would love your thoughts, please comment.x
()
x