CAC104 Halva - CRACK-A-CODE 1.0 EDITORIAL

PROBLEM LINK:

Halva

Author: Mayuresh Patle
Tester: Mayuresh Patle
Editorialist: Mayuresh Patle

DIFFICULTY:

CAKEWALK

PREREQUISITES:

Strings

PROBLEM:

Print “sugar” if input string is “milk” and “milk” if input string is “sugar”.

EXPLANATION:

Input the string and check its first character:

  • If it is ‘s’ then print “milk”
  • Otherwise print “sugar”

SOLUTION:

Setter's Solution
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    string s;
    cin>>t;
    while(t--)
    {
        cin>>s;
        cout<<(s[0]=='s'?"milk":"sugar")<<"\n";
    }
    return 0;
}