斯诺登的密码
題意
找出句子中所有用英文表示的數字(≤20),將這些數字平方后%100,如00,05,11,19,86,99。把這些兩位數按數位排成一行,組成一個新數,如果開頭為0,就去0。找出所有排列方法中最小的一個數,即為密碼。
分析
先計算出每一個數字的平方,不過在放進數組里時,只放兩位。
如1的平方是1,放進數組里時則變成01。
如10的平方是100,放進數組里時則變成00。
最后排序再輸出。
var
i,j:longint;
a:array[0..20]of string;
s,zfc,sz:string;
dz:int64;
begin
? ? read(s);
? ? dz:=0;
? ? repeat
? ? ? ? ?sz:=copy(s,1,pos(' ',s)-1);
? ? ? ? ?if (sz='one')or(sz='One')or(sz='a')or(sz='another')or(sz='first') then
? ? ? ? ?begin
? ? ? ? ? ? ?inc(dz);
? ? ? ? ? ? ?a[dz]:='01';
? ? ? ? ?end else
? ? ? ? ?if (sz='two')or(sz='Two')or(sz='both')or(sz='second') then
? ? ? ? ?begin
? ? ? ? ? ? ?inc(dz);
? ? ? ? ? ? ?a[dz]:='04';
? ? ? ? ?end else
? ? ? ? ?if (sz='three')or(sz='Three')or(sz='third') then
? ? ? ? ?begin
? ? ? ? ? ? ?inc(dz);
? ? ? ? ? ? ?a[dz]:='09';
? ? ? ? ?end else
? ? ? ? ?if (sz='four')or(sz='Four') then
? ? ? ? ?begin
? ? ? ? ? ? ?inc(dz);
? ? ? ? ? ? ?a[dz]:='16';
? ? ? ? ?end else
? ? ? ? ?if (sz='five')or(sz='Five') then
? ? ? ? ?begin
? ? ? ? ? ? ?inc(dz);
? ? ? ? ? ? ?a[dz]:='25';
? ? ? ? ?end else
? ? ? ? ?if (sz='six')or(sz='Six') then
? ? ? ? ?begin
? ? ? ? ? ? ?inc(dz);
? ? ? ? ? ? ?a[dz]:='36';
? ? ? ? ?end else
? ? ? ? ?if (sz='seven')or(sz='Seven') then
? ? ? ? ?begin
? ? ? ? ? ? ?inc(dz);
? ? ? ? ? ? ?a[dz]:='49';
? ? ? ? ?end else
? ? ? ? ?if (sz='eight')or(sz='Eight') then
? ? ? ? ?begin
? ? ? ? ? ? ?inc(dz);
? ? ? ? ? ? ?a[dz]:='64';
? ? ? ? ?end else
? ? ? ? ?if (sz='nine')or(sz='Nine') then
? ? ? ? ?begin
? ? ? ? ? ? ?inc(dz);
? ? ? ? ? ? ?a[dz]:='81';
? ? ? ? ?end else
? ? ? ? ?if (sz='ten')or(sz='Ten') then
? ? ? ? ?begin
? ? ? ? ? ? ?inc(dz);
? ? ? ? ? ? ?a[dz]:='00';
? ? ? ? ?end else
? ? ? ? ?if (sz='eleven')or(sz='Eleven') then
? ? ? ? ?begin
? ? ? ? ? ? ?inc(dz);
? ? ? ? ? ? ?a[dz]:='21';
? ? ? ? ?end else
? ? ? ? ?if (sz='twelve')or(sz='Twelve') then
? ? ? ? ?begin
? ? ? ? ? ? ?inc(dz);
? ? ? ? ? ? ?a[dz]:='44';
? ? ? ? ?end else
? ? ? ? ?if (sz='thirteen')or(sz='Thirteen') then
? ? ? ? ?begin
? ? ? ? ? ? ?inc(dz);
? ? ? ? ? ? ?a[dz]:='69';
? ? ? ? ?end else
? ? ? ? ?if (sz='fourteen')or(sz='Fourteen') then
? ? ? ? ?begin
? ? ? ? ? ? ?inc(dz);
? ? ? ? ? ? ?a[dz]:='96';
? ? ? ? end else
? ? ? ? if (sz='fifteen')or(sz='Fifteen') then
? ? ? ? ?begin
? ? ? ? ? ? ?inc(dz);
? ? ? ? ? ? ?a[dz]:='25';
? ? ? ? ?end else
? ? ? ? ?if (sz='sixteen')or(sz='Sixteen') then
? ? ? ? ?begin
? ? ? ? ? ? ?inc(dz);
? ? ? ? ? ? ?a[dz]:='56';
? ? ? ? ?end else
? ? ? ? ?if (sz='seventeen')or(sz='Seventeen') then
? ? ? ? ?begin
? ? ? ? ? ? ?inc(dz);
? ? ? ? ? ? ?a[dz]:='89';
? ? ? ? ?end else
? ? ? ? ?if (sz='eighteen')or(sz='Eighteen') then
? ? ? ? ?begin
? ? ? ? ? ? ?inc(dz);
? ? ? ? ? ? ?a[dz]:='24';
? ? ? ? ?end else
? ? ? ? ?if (sz='nineteen')or(sz='Nineteen') then
? ? ? ? ?begin
? ? ? ? ? ? ?inc(dz);
? ? ? ? ? ? ?a[dz]:='61';
? ? ? ? ?end else
? ? ? ? ?if (sz='twenty')or(sz='Twenty') then
? ? ? ? ?begin
? ? ? ? ? ? ?inc(dz);
? ? ? ? ? ? ?a[dz]:='00';
? ? ? ? end;
? ? ? ? ?delete(s,1,pos(' ',s));
? ? until s[1]='.';
? ? for i:=1 to dz-1 do
? ? begin
? ? ? ? for j:=i+1 to dz do
? ? ? ? if a[i]>=a[j] then
? ? ? ? begin
? ? ? ? ? ? a[0]:=a[i];a[i]:=a[j];a[j]:=a[0];
? ? ? ? end;
? ? end;
? ? zfc:='';
? ? for i:=1 to dz do
? ? zfc:=zfc+a[i];
? ? val(zfc,dz);
? ? write(dz);
end.
轉載于:https://www.cnblogs.com/YYC-0304/p/9500198.html
總結
- 上一篇: [USACO1.5]数字金字塔 Numb
- 下一篇: 你要的飞碟在这儿