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 n, string s){int cnt = 0;for (int i = 0; i < n; i++){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(n, s) << "\n";return 0;}
No comments:
Post a Comment