Huawei Machine test-translate phone number

Source: Internet
Author: User
Tags alphabetic character

For example:

Input: Onetwothree

Output: 123


Input: Onetwodoubletwo

Output: 1222


Input: 1TWO2

Output: ERROR


Input: Doubledoubletwo

Output: ERROR


There are spaces, illegal characters, two double connections, double in the last word is wrong.

#include <iostream> #include <string> using namespace std; void process (String str) {//the subscript of each string is its corresponding Arabic numeral char *ch[]={"zero", "one", "one", "three", "four", "five", "six    "," Seven "," eight "," Nine "," Double "};char *out[100];//store result set int f=0;      int i,j,k;        String substr;     int Len=str.length ();  int flag=0;//judge Double appears int flag2=0;//The inner loop has no break for (i=0;i<len;i++) {if (Flag2) break;else if (str[i]<97 | | str[i]>122)//non-alphabetic character {out[f++]= "error"; break;}    else{//can be seen with a minimum of 3 characters and a maximum of 6 characters for (j=i+2;j<len&& (j-i) <6;j++) {substr=str.substr (i,j-i+1); if (!substr.compare (CH[10))//appears double{if (i==len-6)//Last double{out[f++]= "error"; flag2=1;break;} else if (flag) {//two consecutive doubleout[f++]= "error"; flag2=1;break;} Elseflag=1;} Else{for (k=0;k<10;k++) {if (!substr.compare (Ch[k])) {if (flag) {out[f++]=ch[k];out[f++]=ch[k];flag=0;break;}   ELSE{OUT[F++]=CH[K]; Break;}} }}}}} int flag3=0;//See if there is an error, the default is no errorfor (int r=0;r<f;r++) {if (out[r]== "error")//has errorflag3=1;} if (!FLAG3) for (r=0;r<f;r++) for (k=0;k<10;k++) {if (Out[r]==ch[k]) printf ("%d", k);}    elseprintf ("error");  printf ("\ n");        } void Main () {string str; while (Getline (CIN,STR)) process (str);   }



Huawei Machine test-translate phone number

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.