Problem link: CodeChef: Practical coding for everyone
Setter:Ankur Pandey
Tester:Ankur Pandey
Difficulty:
Simple
Time Complexity:O(n)
Problem:…
Explanation: Let k_ a will be amount of characters “V” in the string and k_d will be amount of characters “H” in the string. Then, if k_a > k_d , we print “Virat”. If k_a < k_d , we print “Harshit”. If k_a = k_d , we print “Friendship”.
#include
using namespace std;
int main()
{
int n; cin >> n;
string s; cin >> s;
int k_a = 0, k_d = 0;
for (int i = 0; i < n; i++)
if (s[i] == 'V') k_a++; else k_d++;
if (k_a > k_d) cout << "Virat" << endl;
if (k_a < k_d) cout << "Harshit" << endl;
if (k_a == k_d) cout << "Friendship" << endl;
return 0;
}