Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
C++ code to check phone number can be formed from numeric string
Suppose we have a string S with n digits. A number with exactly 11 digits is a telephone number if it starts with '8'. In one operation, we can remove one digit from S. We have to check whether we can make the string a valid phone number or not.
So, if the input is like S = "5818005553985", then the output will be True, because we can make the string "8005553985" with 11 characters and first digit is 8.
Steps
To solve this, we will follow these steps −
m := size of S insert '8' at the end of S if if location of 8Example
Let us see the following implementation to get better understanding −
#includeusing namespace std; bool solve(string S){ int m = S.size(); S.push_back('8'); if ((int(S.find('8')) Input
"5818005553985"Output
1
Advertisements
