Dream Friend CSTR02

Problem link:
Practice
Contest link

Author: Ekansh Saxena
Tester: Ujjawal Gupta
Editorial: Ekansh Saxena

Difficulty:
Easy

Prerequisite:
String, C++ stl.

Algorithm:-
Here, we can divide the problem into the two parts:

  1. Calculate the weight of given friend’s name.
  2. Check whether he/she will be Kevin’s dream friend or not.

For the first part, Create a variable named “count” to store the weight and then simply loop through the given string and keep incrementing the value of “count” by the weight of each alphabet present in the string.
Weight of ‘d’ can be calculated as ‘d’ - ‘a’.

For the second part, just add “count” with 61 (weight of “Kevin”) and if the result obtained is even then print “YES”, otherwise “NO”.

Solution:-

Tester's Code

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

//Execution of logical function.
string logical_function(){
long long count=0,i,j,k;
string s;
cin>>k;
cin>>s;
for(i=0;i<k;i++)
count+=s.at(i);
if(count &1) return “YES”;
return “NO”;
}
//Execution of Main Function.
int main(){
long long t;
cin>>t;
while(t–){
cout<<logical_function()<<endl;
//cout<<answer.
}
}