华为机试 翻译电话号码

网上找的程序,比较简洁,用到了strncmp函数:
// huawei_22.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main()
{
   char a[11][11]={"zero","one","two","three","four","five","six","seven","eight","nine","double"};
   char *s,out[20];
   int i=0,j=0,f=0,d=0,k=0,count=0;
  
   s=(char *)malloc(sizeof(char));
   gets(s);
  
   while(*s!='\0')
   {
    f=0;
    if(*s=='Z'||*s=='O'||*s=='T'||*s=='F'||*s=='S'||*s=='E'||*s=='N'||*s=='D')
     *s+=32;
     for(i=0;i<11;i++)
  {
   if(!strncmp(s,a[i],strlen(a[i])) && i<10)
   {    out[k++]=i+'0';
        s=s+strlen(a[i]);
     f=1;
     if(d==1)
     {
       out[k++]=i+'0';
    d=0;
     }
   }
   else if(!strncmp(s,a[i],strlen(a[i])) && i==10)
   {
      d=1;
   f=1;
   s=s+strlen(a[i]);
   count++;
   }
  }
  if(f==0|| count>1)
  {
    printf("error!\n");
    return 0;
  }
   }
   out[k]='\0';
   if(d==1)
    printf("error!\n");
   else
    puts(out);
   getchar();
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值