 PRACTICE

Easy

Number Theory

# PROBLEM:

A number is called ‘Valentine number’ when the sum of the digits is even but the number is itself odd.
You are given a non-negative integer s, consisting of n digits. You can delete some digits to make the given number Valentine, without changing the order of the digits. The resulting number shouldn’t contain leading zeros. You can delete any number of digits between 0 (do not delete any digits at all) and n−1.
Find any resulting number that is Valentine and print “committed”. If it’s impossible to create a Valentine number print “single”.

### Input:

The first line contains a single integer t.
The first line of each test case contains a single integer n (the number of digits in the original number).
The second line of each test case contains a non-negative integer number s, consisting of n digits.

### Output:

If it’s possible to make a Valentine number after deleting some, possibly zero, but not all digits then print “committed” (without quotes).
If it is impossible then print “single” (without quotes).

### Constraints: -

t (1<= t <=100)
n (1 <= n <= 1000)

## Example 1:-

3
2
14
3
123
3
525

single
committed
committed

### Explanation: -

14 sum is odd so “single”

# EXPLANATION:

A number is called ‘valentine’ when the sum of its digits is even but the number is itself odd.
For a number to be odd, the last digit of the number must be odd. And for it to be ‘valentine’ there must be at least 1 more digit to make the sum even.
We know that to make the sum of some digits even, when one of them is odd, we need at least one more odd digit (since odd + odd = even). Thus to make a valentine number from a number, we need at least 2 odd digits. Since, there is no restriction on the size of valentine number, we can simply make a 2 digit valentine number by choosing two odd digits out of the given number (in given order). If the given number does not contain 2 odd digits, we cannot make a valentine number out of it, and we simply print “single”
Else we print “committed”.

# SOLUTION:

``````#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
string num;
cin>>num;
string ans = "";
for(int i =0;i<n;i++)
{
int digit = num[i]-'0';
if((digit)%2==1)
ans= ans+num[i];

if(ans.size()==2)
break;
}

if(ans.size()==2)
cout<<"committed"<<endl;

else
cout<<"single"<<endl;
}
return 0;
}``````