华为上机英文数字翻译
来源:互联网 发布:excel文档修复软件 编辑:程序博客网 时间:2024/06/05 08:56
原题:
将 电话号码 one two 。。。nine zero
翻译成1 2 。。9 0
中间会有double
例如输入:OneTwoThree 输出:123
输入:OneTwoDoubleTwo 输出:1222
输入:1Two2 输出:ERROR
输入:DoubleDoubleTwo 输出:ERROR
第三题:有空格,非法字符,两个Double相连,Double位于最后一个单词 都错误
贴代码,不怎么简洁:
#include <iostream>#include <string.h>using namespace std; int main(){char s[100];while(cin>>s){int in=0,first=0,second=0 ,last=0;char up='a';while(s[in]!='\0'){if(s[in]==' '){cout<<"error"<<endl;return 0;}if(s[in]>='A' && s[in]<='Z'){up=s[in];if(s[in]=='D'){if(first==0){first=1;}else{cout<<"error"<<endl;return 0;}}else{first=0;}}in++;}if(up=='D'){cout<<"error"<<endl;break;}char str[11][11]={"Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Double"};int i=0,j=0,m,d=0;char temp[11];while (s[i]!='\0'){temp[j++]=s[i];if (s[i]>='A' && s[i]<='Z'){if(i!=0){temp[j-1]='\0';j=0;for(m=0;m<11;m++){if(!strcmp(temp,str[m]) && m<10){cout<<m;if(d==1){cout<<m;d=0;}break;}else if(!strcmp(temp,str[m]) && m==10){d=1;break;}}temp[j++]=s[i];}}i++;}temp[j]=s[i];if(i!=0){temp[j]='\0';j=0;for(m=0;m<11;m++){if(!strcmp(temp,str[m]) && m<10){cout<<m;if(d==1){cout<<m;d=0;}}}}cout<<endl;} return 0;}
0 0
- 华为上机英文数字翻译
- 华为上机练习题--将英文号码翻译成数字号码
- 华为上机—电话号码翻译
- 华为上机试题:数字问题.
- 华为上机练习题--大数字的运算
- 华为2013上机题目 五个数字加减
- 翻译1-5的数字的英文
- 英文数字写法翻译阿拉伯数字 [java实现]
- 数字的翻译(英文到中文)
- 华为上机练习题--判断某数字是否是回文数字
- 电话号码翻译(华为上机试题8_31_3)
- 华为上机测试题(数字字符串转二进制-java)
- 2016华为上机题:挑选出现最多的数字
- 翻译英文
- 华为2012年上机考试------一副牌中发五张扑克牌给你:让你判断数字的组成
- 华为Java上机题
- 华为上机题目-3
- 一道华为上机题
- OpenGL + VS2010 配置整理
- JFinal
- 求解Ax=b:可解性和解的结构
- uva 10368 - Euclid's Game(博弈)
- 素数筛选法(模板)
- 华为上机英文数字翻译
- CodeForces 25E Test KMP
- hdu-4656-So Easy!-递推式+矩阵优化
- 关于掉电保存数据的思考
- CAS SSO 工作机制(每一步请求详述)
- OpenCV学习笔记7 OpenCV核心模块与核心功能Core Module & Core Functionality(六)
- 编程语言类型划分
- C++ 内存管理(memory Management) part1
- Aurora中Problems running LaTex的解决方案 && Aurora2.x注册机