clear all;
clc;
tic
s=0;
t=input('请输入一个1-1000的数字\n');
for a=1:t
b=num2str(a);
c=length(b);
d=num2str(a);
A={'zero','one','two','three','four','five','six','seven','eight','nine'};
B={'ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen','twenty'};
C={'ten','twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety'};
D={'one hundred','two hundred','three hundred','four hundred','five hundred','six hundred','seven hundred','eight hundred','nine hundred'};
if c==1
disp([num2str(a),' is ',char(A(a+1))]);
e=length(char(A(a+1)));
end
if c==2
if a>=10&&a<=20
disp([num2str(a),' is ',char(B(a-10+1))]);
e=length(char(B(a-10+1)));
elseif (a>20&&a<=99)&&(mod(a,10)~=0)
disp([num2str(a),' is ',char(C(str2double(d(1)))),' - ',char(A(str2double(d(2))+1))]);
e=length(char(C(str2double(d(1)))))+length(char(A(str2double(d(2))+1)));
elseif mod(a,10)==0
disp([num2str(a),' is ',char(C(str2double(d(1))))]);
e=length(char(C(str2double(d(1)))));
end
end
if c==3
if mod(a,100)==0
disp([num2str(a),' is ',char(D(str2double(d(1))))])
e=length(char(D(str2double(d(1)))))-1;
end
if mod(a,10)==0&&mod(a,100)~=0
disp([num2str(a),' is ',char(D(str2double(d(1)))),' and ',char(C(str2double(d(2))))]);
e=length(char(D(str2double(d(1)))))-1+3+length(char(C(str2double(d(2)))));
end
if mod(a,10)~=0
if d(2)=='0'
disp([num2str(a),' is ',char(D(str2double(d(1)))),' and ',char(A(str2double(d(3))+1))]);
e=length(char(D(str2double(d(1)))))-1+3+length(char(A(str2double(d(3))+1)));
elseif d(2)=='1'
disp([num2str(a),' is ',char(D(str2double(d(1)))),' and ',char(B(str2double(d(3))+1))]);
e=length(char(D(str2double(d(1)))))-1+3+length(char(B(str2double(d(3))+1)));
else
disp([num2str(a),' is ',char(D(str2double(d(1)))),' and ',char(C(str2double(d(2)))),' ',char(A(str2double(d(3))+1))]);
e=length(char(D(str2double(d(1)))))-1+3+length(char(A(str2double(d(3))+1)))+length(char(C(str2double(d(2)))));
end
end
end
if a==1000
disp([num2str(a),' is one thousand']);
e=length('one')+length('thousand');
end
disp(['the length of the number ',num2str(a),' is ',num2str(e)]);
s=s+e;
end
disp(['the number of the used letter is ',num2str(s)]);
toc