COUNT NUMBERS

Your task is pretty simple, given a string S , find the total count of numbers present in the digit.

Example:

Input:  n = 26, s = "sadw96aeafae4awdw2wd100awd"
Output: 4

Approach

C++

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

int countNumbers(int nstring s)
{

    int cnt = 0;
    for (int i = 0i < ni++)
    {
        if (s[i] >= '0' && s[i] <= '9')
        {
            while (i < n && s[i] >= '0' && s[i] <= '9')
                i++;
            cnt++;
        }
    }
    return cnt;
}
int main()
{

    int n = 26;

    string s = "sadw96aeafae4awdw2wd100awd";

    cout << countNumbers(ns<< "\n";

    return 0;
}


No comments:

Post a Comment