Day 8 Challenge Yourself

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Sri Krishna College of Engineering and Technology

Name :Thiruvenpha T Email :23ec201@skcet.ac.in


Roll no:23EC201 Phone :8870764502
Branch :SKCET Department :ECE-C
Batch :2023_27 Degree :BE-ECE

2023_27_I_PS using CPP_IRC

PSCPP_String_CY

Attempt : 1
Total Mark : 50
Marks Obtained : 38

Section 1 : Coding

1. Casper at the Carnival


The Circoloco Children Carnival is the City’s largest and successful event
dedicated to children and families. Casper is a smart little boy who loves
eating cookies and drinking fresh juices. He visits the carnival with his
parents and is going to spend N minutes at the event ground. Each minute
he either eats a cookie or drinks fresh juice. Cookies are very sweet and
thus Casper’s parents have instructed him to drink fresh juice in the next
minute, after eating a cookie.

You are given whether he ate a cookie or drank fresh juice in each of the N
minutes. Your task is to check if Casper followed his parents' instructions.
That is, you need to verify whether after each eaten cookie he drinks fresh
juice in the next minute.

Answer
// You are using GCC
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
int n;
cin>>n;
string a[n];
for(int i=0;i<n;i++)
cin>>a[i];
int c=0;
for(int i=0;i<n;i++)
{
if(a[i]=="cookie"&&a[i+1]!="juice")
{
c++;
break;
}
}
if(c)
{
cout<<"No"<<endl;
}
else
{
cout<<"Yes"<<endl;
}
}

Status : Correct Marks : 10/10

2. Wildcard Matching:

Sunil is a little scientist. Sunil has planned to design a wildcard pattern


matcher to exhibit at the "Young Inventors", a tech talent show organized at
his school. Sunil wanted to design the wildcard pattern matcher supporting
the wildcard character '?'. The wildcard character '?' can be substituted by
any single lowercase English letter for matching. He has two strings X and
Y of equal length, made up of lowercase letters and the character '?'. Sunil
wants your help in designing the device, to know whether the strings X and
Y can be matched or not. Write a program to check whether the given
strings can be matched or not.

Answer
// You are using GCC
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
string x,y;
cin>>x>>y;
//if(x.length() != y.length())
/* {
cout<<"No"<<endl;
return 0;
}*/
for(int i=0;i<x.length();i++)
{
if(x[i]!=y[i]&& x[i] !='?'&&y[i] !='?')
{
cout<<"No"<<endl;
return 0;
}
}
cout<<"Yes"<<endl;
return 0;
}

Status : Partially correct Marks : 8/10

3. Write a program to remove the characters which have odd index values
of a given string

Answer
// You are using GCC
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
string a;
cin>>a;string result;
for(int i=0;i<a.length();i+=2)
{
result+=a[i];
}
cout<<result;
}

Status : Wrong Marks : 0/10

4. Write a program to get a string from user and remove all characters in
that string except alphabets.

Answer
// You are using GCC
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
string a,temp="";
cin>>a;
int n=a.length();
for(int i=0;i<n;i++)
{
if((a[i]>='A'&&a[i]<='Z')||(a[i]>='a'&&a[i]<='z'))
{
temp=temp+a[i];
}
}
a=temp;
cout<<a;
}

Status : Correct Marks : 10/10

5. Toggle each character in a string. (From lower case to upper case and
vice versa). If any special characters are found, leave it as it is.

Answer
// You are using GCC
#include<iostream>
#include<cctype>
#include<cstring>
using namespace std;
int main()
{
string input;
getline(cin,input);
for(char &c:input)
{
if(islower(c))
c=toupper(c);
else if(isupper(c))
c=tolower(c);
}
cout<<input<<endl;
return 0;
}

Status : Correct Marks : 10/10

You might also like