8/14/2018 - 11:03 AM

Check Whether a number is Duck Number or not

A Duck number is a number which has zeroes present in it, but there should be no zero present in the beginning of the number. For example 3210, 8050896, 70709 are all duck numbers whereas 02364, 03401 are not. The task is to check whether the given number is a duck number or not.

Examples :

Input : 707069 Output : It is a duck number. Explanation: 707069 does not contains zeros at the beginning.

Input : 02364 Output : It is not a duck number. Explanation: in 02364 there is a zero at the beginning of the number.

using namespace std;

bool func (string s) {
    if (s[0]=='0')
        return 0;
    for (int i=1;i<s.length();i++)
        if (s[i]=='0')
            return 1;
    return 0;

int main() {
    string s;
    getline(cin, s);
    if (func(s))
        cout<< "Its a Duck!";
        cout<< "Nope";