华为上机英文数字翻译

原题:

将 电话号码 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;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值