Use matlab programming to "translate" numbers into English

Use matlab programming to "translate" numbers into English

An experiment of algorithm design:
Title: "Translate" numbers into English with matlab programming. "Translate" numbers into English with matlab programming. Such as: 35706 "translated" into three-five-seven-zero-six.
[Algorithm design]:
1) The number generally has many digits, which can be input and stored as a long integer.
2) Store the English "zero-nine" in the array, and the corresponding subscripts are 0-9. In this way, words without numerical rules can be easily accessed and accessed through subscripts.
3) Through the remainder and rounding operations, each digit of the number can be obtained. Use this number as a subscript, just to find the corresponding English number.
4) Considering that the output translation result is carried out from the high order to the low order, and taking each number, the simpler method is to start from the low order and complete it step by step through the remainder and integer division operations. Therefore, it is necessary to open an array to store the translated result from the low order to the high order, and record the number of digits, and finally output the result from the high order to the low order in reverse.
[Pseudo code implementation]
main( )
{int i,a[10], ind; long num1,num2;
char eng[10][6]={“zero”,”one”,”two”,”three”, "four",
"five","six","seven","eight","nine"};
print("Input a num");
input(num1); num2=num1; ind =0;
while (num2 <>0)
{a[ind]=num2 mod 10; ind= ind +1; num2=num2/10; }
print(num1, “English_exp:”, eng[a[ind-1]]);
for( i=ind-2;i>=0;i=i-1)
print(“-”,eng[a[i]]);
}

%author Canlong
charNum = {'zero','one','two','three','four','five','six','seven','eight','nine'};
num = 1570232324343232434;
remNum =[] ;
i=0;
%取各个数字
while floor(num)~=0
i=i+1;
remNum(i) = mod(num,10);
num = floor(num/10);
end
%取出数组中的元素
for j=i:-1:1
   index = remNum(j) + 1;
   fanyi = charNum{index};
   fprintf('%s',fanyi)
   if j~=1
     fprintf('-')
   end
end
disp(' ');

Questions and Summary

If the integer is too large, the translation cannot be implemented at present, and an error will be reported, and num will be converted to a large integer later.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325685736&siteId=291194637