Hua Wei 机试题目一
一、身份证号码验证
题目描述:
我国公民的身份证号码特点如下:
1、 长度为18位;
2、 第1~17位只能为数字;
3、 第18位可以是数字或者小写英文字母x。
4、 身份证号码的第7~14位表示持有人生日的年、月、日信息。
例如:511 002 1988 08 08 0111或51100219880808011x。
请实现身份证号码合法性判断的函数。除满足以上要求外,需要对持有人生日的年、月、日信息进行校验。年份大于等于1900年,
小于等于2100年。需要考虑闰年、大小月的情况。
所谓闰年,能被4整除且不能被100整除 或 能被400整除的年份,闰年的2月份为29天,非闰年的2月份为28天。
其他情况的合法性校验,考生不用考虑。
int verifyID(char* inID)
函数返回值:
1) 如果身份证号合法,返回0;
2) 如果身份证号长度不合法,返回1;
3) 如果身份证号第1~17位含有非数字的字符,返回2;
4) 如果身份证号第18位既不是数字也不是英文小写字母x,返回3;
5) 如果身份证号的年信息非法,返回4;6-9
6) 如果身份证号的月信息非法,返回5;10-11
7) 如果身份证号的日信息非法,返回6(请注意闰年的情况);12-13
【注】除成功的情况外,以上其他合法性判断的优先级依次降低。也就是说,如果判断出长度不合法,直接返回1即可,不需要再做其他合法性判断。
二、手机号码验证
问题描述:
我国大陆运营商的手机号码标准格式为:国家码+手机号码,例如:8613912345678。特点如下:
1、 长度13位;
2、 以86的国家码打头;
3、 手机号码的每一位都是数字。
请实现手机号码合法性判断的函数要求:
1) 如果手机号码合法,返回0;
2) 如果手机号码长度不合法,返回1
3) 如果手机号码中包含非数字的字符,返回2;
4) 如果手机号码不是以86打头的,返回3;
【注】除成功的情况外,以上其他合法性判断的优先级依次降低。也就是说,如果判断出长度不合法,直接返回1即可,不需要再做其他合法性判断。
要求实现函数:
int verifyMsisdn(char* inMsisdn)
【输入】 char* inMsisdn,表示输入的手机号码字符串。
【输出】 无
【返回】 判断的结果,类型为int。
示例
输入: inMsisdn = “869123456789“
输出: 无
返回: 1
输入: inMsisdn = “88139123456789“
输出: 无
返回: 3
输入: inMsisdn = “86139123456789“
输出: 无
返回: 0
(给的例子都不是13位,应该都返回1)
三、邮箱合法性验证
Title Description:
Compile a function for verifying validity of a mailbox address. The mailbox address is valid if the following conditions are met:
1. 地址中只能有一个 '@' .
2.最后三位必须是 ".com".
3. 字符之间没有空格.
4.有效地字符: 1~9, a~z, A~Z, '.', '@', '_'.
返回结果1表示该邮箱是合法的. 返回 0 表示该邮箱不合法.
To complete the following function:
void vConvertMsg(char *pInputStr, long lInputLen, char *pOutputStr);
[Input]
char *pInputStr: a pointer pointing at an array
long lInputLen: length of the array
char *pOutputStr: output result displayed as character strings. '1' indicates a valid mailbox address. '0' indicates an invalid mailbox address. '\0' indicates the end of the character string.
[Return] None
[Note] You only need to complete the function algorithm, without any IO output or input.
Example
Input: huawei@huawei.com
Return: 1
Input: aa@ddd@huawei.com
Return: 0
实现如下:
一、身份验证
int isLeapYear(int year)
{
if ((year%== && year%!=) || year%==)
{
return ;
}
else
return ;
}
int verifyID(char* inID)
{
int len=strlen(inID);
if (len!=)
{
return ;
}
for (int i=;i<len-;i++)
{
if (inID[i]<'' || inID[i]>'')
{
return ;
}
}
if (((inID[len-]>='' && inID[len-]<='') || inID[len-]=='x')==false)
{
return ;
}
string temp=inID;
string temp1=temp.substr(,);
int year=;
for (int i=;i<;i++)
{
year=year*+temp1[i]-'';
}
//cout<<year<<" ";
if (year< || year>)
{
return ;
}
string temp2=temp.substr(,);
int month=;
for (int i=;i<;i++)
{
month=month*+temp2[i]-'';
}
//cout<<month<<" ";
if (month< || month>)
{
return ;
}
string temp3=temp.substr(,);
int day=;
for (int i=;i<;i++)
{
day=day*+temp3[i]-'';
}
//cout<<day<<" ";
if (month==)
{
if (isLeapYear(year))
{
if (day< || day>)
{
return ;
}
}
else
{
if (day< || day>)
{
return ;
}
}
}
else if (month== || month== || month== || month== || month== || month== || month==)
{
if (day< || day>)
{
return ;
}
}
else
{
if (day< || day>)
{
return ;
}
} return ;
} 二、手机号码验证
int verifyMsisdn(char* inMsisdn)
{
int len = strlen(inMsisdn);
if (len!=)
{
return ;
}
int i=;
for (;i<len;i++)
{
if (inMsisdn[i]<'' || inMsisdn[i]>'')
{
return ;
}
} if (inMsisdn[]!='' || inMsisdn[]!='')
{
return ;
} if (i==len)
{
return ;
} }
三、邮箱地址验证
void vConvertMsg(char *pInputStr, long lInputLen, char *pOutputStr)
{
int countOfAt=;
int countOfSpace=;
int countOfError=;
int i=;
for (;i<lInputLen;i++)
{
if (pInputStr[i]=='@')
{
countOfAt++;
}
if (pInputStr[i]==' ')
{
countOfSpace++;
}
if (((pInputStr[i]>='' && pInputStr[i]<='') || (pInputStr[i]>='a'
&& pInputStr[i]<='z') || (pInputStr[i]>='A' && pInputStr[i]<='Z')
|| pInputStr[i]=='_' || pInputStr[i]=='.' || pInputStr[i]=='@')==false)
{
countOfError++;
}
}
if (countOfAt!= || countOfSpace!= || countOfError!=)
{
*pOutputStr=+'';
cout<<*pOutputStr<<endl;
return;
}
if (pInputStr[i-]!='m' || pInputStr[i-]!='o' || pInputStr[i-]!='c' || pInputStr[i-]!='.')
{
*pOutputStr=+'';
}
else
*pOutputStr=+''; cout<<*pOutputStr<<endl; }
Hua Wei 机试题目一的更多相关文章
- Hua Wei 机试题目三---2014
一.根据对应规则进行翻译输出 描述:已知有如下的对应规则: ,则输入任意个正整数,输出经过规则翻译以后对应的结果. 例如:输入:1234:输出bcde. 题目很简单,我觉得需要注意的问题就是对于大整数 ...
- Hua Wei 机试题目二
题目描述:假设1元,5元,10元,50元,100元的人民币若干,实现一个能找到最少张数累计达到一个指定金额方法.如:67元,可分为67个1元钱.也可分为6个10元7个1元,其中最少人民币分法为一张50 ...
- Hua Wei 机试题目四---2014
一.计算亮灯的个数 描述:一条长廊里依次装有n(1≤n≤65535)盏电灯,从头到尾编号1.2.3.…n-1.n.每盏电灯由一个拉线开关控制.开始,电灯全部关着. 有n个学生从长廊穿过.第一个学生把号 ...
- 9月5日 华为2014校园招聘的机试题目_C语言版答案
手有些生了. 题目: 通过键盘输入一串小写字母(a~z)组成的字符串.请编写一个字符串压缩程序,将字符串中连续出席的重复字母进行压缩,并输出压缩后的字符串.压缩规则:1.仅压缩连续重复出现的字符.比如 ...
- Java机试题目_怎样截取字符串
面试题1 怎样截取字符串 考题题干 编写一个截取字符串的函数,输入为一个字符串和字节数,输出为按字节截取的字符串.但是要保证汉字不被截半个,如"我ABC"4,应该截为" ...
- 一道来自华为的C机试题目
题目是这样的 求一个字符串中连续字母的个数 比如I have a book. : 1 I have a dog. : 0 I haavee aa dogg : 4 #include <windo ...
- 华为OJ机试题目:两个大整数相乘(纯C语言实现两个大整数相乘,两种方法实现大数相乘)
题目描述: 输出两个不超过100位的大整数的乘积. 输入: 输入两个大整数,如1234567 123 输出: 输出乘积,如:151851741 样例输入: 1234567 123 样例输出: 1518 ...
- 华为2013年西安java机试题目:如何过滤掉数组中的非法字符。
这道题目为记忆版本: 题目2描述: 编写一个算法,过滤掉数组中的非法字符,最终只剩下正式字符. 示例:输入数组:“!¥@&HuaWei*&%123” 调用函数后的输出结果,数组:“Hu ...
- 九度oj 题目1083:特殊乘法 清华大学2010年机试题目
题目描述: 写个算法,对2个小于1000000000的输入,求结果. 特殊乘法举例:123 * 45 = 1*4 +1*5 +2*4 +2*5 +3*4+3*5 输入: 两个小于1000000000的 ...
随机推荐
- Mac使用ssh登录远程linux系统查看jetty日志及同时使用github工具
转载请注明出处:http://www.houxiurong.com/?post=27 Mac默认是安装了ssh工具软件的. 先用mac的 终端工具生成 id_rsa 和id_rsa.pub 秘钥,生成 ...
- 前端web通过flask操作数据库-增删改查
后端python代码: #coding:utf8 from flask import Flask,request,render_template import pymysql as mysql imp ...
- swift Self
'Self' is the type of a protocol/class/struct/enum.And the 'self' is a instance of a class/struct/en ...
- VMware 虚拟化技术 创建虚拟机
原文地址:https://www.linuxidc.com/Linux/2017-03/141972.htm 云最成熟的架构是IaaS(Infrastructure as a Service),其中用 ...
- java 常用API
package com.orcal.demc01; public class Regex { public static void main(String[] args) { // TODO Auto ...
- Java判断字符串中是否含有英文
实现代码: /* * 判断字符串中是否含有英文,包含返回true */ public boolean isENChar(String string) { boolean flag = false; P ...
- BZOJ 1725: [Usaco2006 Nov]Corn Fields牧场的安排 状压动归
Description Farmer John新买了一块长方形的牧场,这块牧场被划分成M列N行(1<=M<=12; 1<=N<=12),每一格都是一块正方形的土地.FJ打算在牧 ...
- Python笔记23------Python统计列表中的重复项出现的次数的方法
https://www.cnblogs.com/hester/p/6197449.html
- 2019-03-28 SQL inner left full
在使用 join 时,on 和 where 条件的区别如下: 1. on 条件是在生成临时表时使用的条件,它不管 on 中的条件是否为真,都会返回左边表中的记录. 2.where 条件是在临时表生成好 ...
- Oracle数据库性能优化基础
1.数据处理分类OLTP,OLAP 2.Oracle特性 3.数据库优化方法论/原则 方法论:自顶向下优化和自底向上优化 3.1 自顶向下优化 3.2 自底向上优化 对于多年的老系统出现性能问题时,就 ...