SUBJECT-VERB AGREEMENT- SEPT003 - EDITORIAL
PROBLEM LINK
Author: codechefsrm
Editorialist : codechefsrm
DIFFICULTY
SIMPLE
PREREQUISITES
Basic programming
PROBLEM
Given a number of sentence/s, following the SUBJECT VERB AGREEMENT in the problem,
correct the given sentences using given instruction and print out the corrected
sentence.
EXPLANATION
Given a string, as we have only four subjects, check if the first word is ‘He’ or
‘She’ or not. If not then print the result as it is. If not then check for correct
subject-verb agreement according to the instruction given in the question, add necessary
suffixes and print the result.
Example Text Case
Input:
2
I play
He sing
Output:
I play
He sings
Note: First sentence is already correct so same is printed out.
The second sentence is corrected by adding ‘s’ in sing and printed.
SOLUTION :
Setter's Solution
#include <iostream>
#include <string>
using namespace std;
int main(){
int t,i;
string s,v;
cin>>t;
for(i=0;i<t;i++){
cin>>s>>v;
if(s=="He"||s=="She"){
if(v[v.length()-1]=='o'){
v= v+"es";
}
else if(v[v.length()-1]=='y'&&v[v.length()-2]!='a'&&v[v.length()-2]!='e'&&v[v.length()-2]!='i'
&&v[v.length()-2]!='o'&&v[v.length()-2]!='u'){
v= v.replace(v.length()-1, 3, "ies");
}
else if(v[v.length()-1]=='h'&&(v[v.length()-2]!='c'||v[v.length()-2]!='s')){
v= v+"es";
}
else{
v=v+'s';
}
cout<<s<<" "<<v<<endl;
}
else{
cout<<s<<" "<<v<<endl;
}
}
}
/*CODE ENDS HERE*/