C + + String programming Training 5

Source: Internet
Author: User

Mobile phone number legality:

1) 13-bit length

2) begin with 86 of the country code

3) Each digit of the mobile phone number is a number

Title: Determine whether the mobile phone number is legitimate, output the corresponding value

Description: function requirements include:

1) legal return 0;

2) The length of the law returns 1;

3) returns 2 if non-numeric characters are included;

4) does not start with 86 and returns 3.

int Legal_phone (const string &str)
{
if (Str.size ()!=13)//Length of judgment
{
return 1;
}
if (str[0]!= ' 8 ' &&str[1]!= ' 6 ')//Whether 86 is the beginning of the judgment
{
return 3;
}
for (int i=0;i<str.size (); i++)//whether there is a non-numeric judgment
{
if (!isdigit (Str[i]))
{
return 2;
}
}
return 0;
}

int main ()
{
String str;
Getline (CIN,STR);
int Res=legal_phone (str);
cout<<res;
}

C + + String programming Training 5

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.