华科15_1
来源:互联网 发布:静默卸载软件 bat 编辑:程序博客网 时间:2024/06/16 00:29
问题:
输入一个字符串,并且进行验证。
条件:
长度必须为11
第一位必须为1
第二位必须为3,5,6,8中的一个
其余任意一位必须为0-9中的一个
分析:
根据规则进行判断即可。
代码:
#include <iostream> #include <stdio.h> #include <string.h> #include <math.h> #include <vector> #include <queue> #include <stack> #include <map> #include <string> #include <algorithm> #include <iomanip>#define MAX 1000using namespace std;/* run this program using the console pauser or add your own getch, system("pause") or input loop */bool isPhoneNum(char * str){//1.长度必须为11位int length=strlen(str) ;if(length != 11){return false;}else{//2.第一位必须为1 第二位为3,5,6,8 其余位必须为0-9中的一个数if(str[0] == '1') {if(str[1] == '3' || str[1] == '5'||str[1] == '6'||str[1] == '8'){//3.其余位必须为0-9中的一个数for(int i=2;i<length;i++) {if(str[i] >'9' || str[i] < '0'){return false;}}}else{return false;}}else{return false;}}return true;}int main(int argc, char** argv) {/*freopen("file/input.txt","r",stdin);freopen("file/output.txt","w",stdout);*/char str[MAX];while(gets(str)){if(isPhoneNum(str)){printf("是一个正确的电话号码!\n");}else{printf("不是一个正确的电话号码!\n");}}return 0;}/*测试用例: 15735186582 157351865822 25735186582 13735186582 16735186582 18735186582 12735186582 17735186582 19735186582 1573518658a */
阅读全文
0 0
- 华科15_1
- 华科14_1
- 算法导论:第15章 动态规划_1钢条切割
- 【Java基础15_1】Collection类及其基本用法
- java _1
- js_trim()_1
- c++_1
- 经典语录_1
- 传知_1
- 练习_1
- 杂记_1
- 4_1
- 3_1
- 11_1
- 8583_1
- 创业_1
- 软件工程_1
- 7_1
- mathjax矩阵输入模板
- 带通滤波器介数如何确定
- C++类和对象
- 十六、数据结构---链表
- Linux 压缩及解压缩文件基础命令操作
- 华科15_1
- PAT (Advanced Level) Practise 1057 Stack (30)
- fgm实例练习笔记-4.1 setTimeout应用
- 【面经笔记】STL库的介绍
- FPGA基础设计(二):PS2键盘控制及短按、长按
- 开发板上修改时间方法date命令【转】
- bzoj 2658: [Zjoi2012]小蓝的好友(mrx) treap+扫描线
- tcp连接超时, 那么可能会出现两次握手后, 客户端发RST包
- android studio 开启multidex支持