Write the Code in C or C++ The School of Languages and Science teaches five subj
ID: 3756360 • Letter: W
Question
Write the Code in C or C++
The School of Languages and Science teaches five subjects: Physics,Chemistry, Math, Botany, and Zoology. There are currently n students enrolled in the school, and each student is skilled in only one subject. The skills of the students are described by string of length n named skills that consists of the letters p, c, m, b, and Z only. Each character i describes the skill of student i as follows p denotes the student is skilled in Physics C denotes the student is skilled in Chemistry. . . m denotes the student is skilled in Math b denotes the student is skilled in Botany z denotes the student is skilled in Zoology For example, if skills is mcmz, then the school has four students where two students are skilled at Math, one student is skilled at Chemistry, and one student is skilled at Zoology. Complete the different Teams function in the editor. It has one parameter: a string, skills. The function must return an integer denoting the total number of different teams satisfying the following constraints: Ateam consists of a group of exactly five students. Each student is skilled in a different subject. Each of the students in the team must not be part of any other team. Input Format Locked stub code in the editor reads a string denoting skills from stdin and passes it to the function. Constraints 5sns5 x 105 skills consists of the letters p, c, m, b, and Z only Output Format The function must return an integer denoting the total number of different five-student teams such that each student is skilled in a different subject and each of the students must not be part of any other team.Explanation / Answer
#include<iostream>
using namespace std;
int find(string s)
{
int a[]={0,0,0,0,0};//to store the count of number of students per each subject
int i=0;
for(i=0;s[i]!='';i++)
{
if(s[i]=='p')a[0]++;
else if(s[i]=='c')a[1]++;
else if(s[i]=='m')a[2]++;
else if(s[i]=='b')a[3]++;
else if(s[i]=='z')a[4]++;
}
//finding number of teams
i=1;
int min=a[0];//the min students in all the subjects is the different number of teams possible
while(i<5)
{
if(a[i]<min)min=a[i];
i++;
}
return min;//
}
int main()
{
//reading input
string s;
cin>>s;
//calling function to find different teams
int t = find(s);
cout<<t<<endl;
return 0;
}
output:
pcmbzzcbmpmcmz
2
Process exited normally.
Press any key to continue . . .
//PLS give a thumbs up if you find this helpful, its helps me alot, thanks
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.