题目
(1)找出句子中所有用英文表示的数字(≤20),列举在下:
正规:one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty
非正规:a both another first second third
(2)将这些数字平方后 mod 100,如00,05,11,19,86,99。
(3)把这些两位数按数位排成一行,组成一个新数,如果开头为0,就去0。
(4)找出所有排列方法中最小的一个数,即为密码。
题解
纯纯的模拟啊,你是多么不可爱!
好好打条件语句(表),天天向上
要注意结果为0的情况需要输出0,还有不要忘了:
非正规:a both another first second third
a(1) another(1) first(1)
both(2) second(2)
third(3)
这些都算数字!
时间复杂度O(120)
代码
const
n:array[1..20]of string=('ONE','TWO','THREE','FOUR','FIVE','SIX','SEVEN',
'EIGHT','NINE','TEN','ELEVEN','TWELVE','THIRTEEN',
'FOURTEEN','FIFTEEN','SIXTEEN','SEVENTEEN',
'EIGHTEEN','NINETEEN','TWENTY');
var
s,a,b:string;
m:array[0..6]of string;
i,j,ans,k,t:longint;
begin
readln(s);
s:=upcase(s);
for i:=1 to 6 do
begin
a:=copy(s,1,pos(' ',s)-1);
for j:=1 to 20 do
if a=n[j] then
begin
inc(t);
str(j*j,m[t]);
delete(m[t],1,length(m[t])-2);
while length(m[t])<2 do m[t]:='0'+m[t];
break;
end;
if (a='A')or(a='ANOTHER')or(a='FIRST') then begin inc(t);m[t]:='01';end;
if (a='BOTH')or(a='SECOND') then begin inc(t);m[t]:='04';end;
if a='THIRD' then begin inc(t);m[t]:='09';end;
delete(s,1,pos(' ',s));
end;
for i:=1 to t-1 do
for j:=i+1 to t do
if m[i]>m[j] then
begin
m[0]:=m[i];
m[i]:=m[j];
m[j]:=m[0];
end;
for i:=1 to t do
b:=b+m[i];
i:=1;
while b[i]='0' do delete(b,1,1);
if b<>'' then writeln(b) else writeln('0');
end.