洛谷1603 斯诺登的密码(第21题)

题目

(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.
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值