华为笔试题09
2013-08-23 11:45
253 查看
题目描述:
编写一个函数检查邮箱地址是否合法,合法的条件是
1、地址中有且只有一个'@'字符
2、最后三位应该是".com"
3、中间没有空格
4、合法的字符是1~9, a~z, A~Z, '.', '@', '_'
正确输出1,非法输出0
要求实现函数:
void vConvertMsg(char *pInputStr, long lInputLen, char *pOutputStr);
【输入】
char *pInputStr:指向一个数组的指针
long lInputLen:该数组的长度
char *pOutputStr:输出结果,按照字符串输出,正确输出字符'1',错误输出字符'0','\0'作为字符串结束符
【返回】 无
【注意】 只需要完成该函数功能算法,中间不需要有任何IO的输入输出
示例
输入:huawei@huawei.com
返回:1
输入:aa@ddd@huawei.com
返回:0
编写一个函数检查邮箱地址是否合法,合法的条件是
1、地址中有且只有一个'@'字符
2、最后三位应该是".com"
3、中间没有空格
4、合法的字符是1~9, a~z, A~Z, '.', '@', '_'
正确输出1,非法输出0
要求实现函数:
void vConvertMsg(char *pInputStr, long lInputLen, char *pOutputStr);
【输入】
char *pInputStr:指向一个数组的指针
long lInputLen:该数组的长度
char *pOutputStr:输出结果,按照字符串输出,正确输出字符'1',错误输出字符'0','\0'作为字符串结束符
【返回】 无
【注意】 只需要完成该函数功能算法,中间不需要有任何IO的输入输出
示例
输入:huawei@huawei.com
返回:1
输入:aa@ddd@huawei.com
返回:0
#include "stdafx.h" #include <iostream> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { char str[]="jinjian.xidian@gmain.com"; int count=0; for(int i=0;i<strlen(str);++i) { if('@'==str[i]) ++count; } if(1!=count) cout<<"error"; if(str[strlen(str)-4]!='.'||str[strlen(str)-3]!='c'||str[strlen(str)-2]!='o'||str[strlen(str)-1]!='m') cout<<"error"; for(int i=0;i<strlen(str);++i) { if(' '==str[i]) cout<<"error"; break; } for(int i=0;i<strlen(str);++i) { if (('1'<=str[i])&&(str[i]<='9')) continue; if (('a'<=str[i])&&(str[i]<='z')) continue; if (('A'<=str[i])&&(str[i]<='Z')) continue; if ('.'==str[i]) continue; if (','==str[i]) continue; if ('@'==str[i]) continue; if ('_'==str[i]) continue; cout<<"error"; break; } return 0; }
相关文章推荐
- 华为2013校园招聘上机笔试题
- 华为、联想等名企笔试题总汇
- 2017年4月21日华为笔试题 德州扑克
- 华为笔试题四
- 华为Java笔试题
- 华为校园招聘笔试题(机考题目)
- 华为笔试题合集
- 2017年华为大牛专场(软件类)校招笔试回忆版
- 华为笔试题:奖金提成
- 华为2011上机笔试题2+参考程序
- 华为笔试题库
- 华为C语言笔试题集合
- 华为研发笔试(随机数查重删除并排序)
- (华为笔试)删数 约瑟夫环问题
- 面试集锦--09网易校园招聘笔试题
- 华为2016校招上机笔试题第一题
- 华为笔试题
- 华为2016校招笔试编程题(扑克牌大小)
- 九月十月百度人搜,阿里巴巴,腾讯华为笔试面试八十题(第331-410题)
- 华为2013校园招聘上机笔试题