Advertisement
Guest User

kelwin

a guest
Oct 17th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.73 KB | None | 0 0
  1. program kewin;
  2. var
  3.   n,n1,a1,b1,c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1,nn1,o1,p1,q1,r1,ss1,t1,u1,v1,w1,x1,y1,z1,a2,b2,c2,d2,e2,f2,g2,h2,i2,j2,k2,l2,m2,n2,o2,p2,q2,r2,s2,t2,u2,v2,w2,x2,y2,z2: int64;
  4.   s,s1 : string;
  5.   bonus: array[1..26] of int64;
  6.   cost : array[1..26] of int64;
  7. procedure output(par:string);
  8. var sum, i:int64;
  9. begin
  10.   sum:=0;
  11.   for i := 1 to length(par) do
  12.    sum:=sum + cost[ord(par[i])-96];
  13.   if n1 < 0  then begin n1:=sum; s1:=par; end;
  14.   if sum< n1 then begin n1:=sum; s1:=par; end;
  15. end;
  16. procedure recurs(str:string;  pos:int64);
  17.  var    i:int64;
  18. begin
  19.    for i := 1 to  bonus[ord(str[length(str)])-96]+1
  20.     do
  21.      if pos+i >= n  then
  22.      output(str+s[n])
  23.      else
  24.      recurs(str+s[pos+i],pos+i);
  25. end;
  26. begin
  27.   n1 := -1;
  28.  readln(n);
  29.  readln(s);
  30.     readln(a2,b2,c2,d2,e2,f2,g2,h2,i2,j2,k2,l2,m2,n2,o2,p2,q2,r2,s2,t2,u2,v2,w2,x2,y2,z2);
  31. readln(a1,b1,c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1,nn1,o1,p1,q1,r1,ss1,t1,u1,v1,w1,x1,y1,z1);
  32.   bonus[1]:=a1 ;bonus[2]:=b1 ;bonus[3]:=c1 ;bonus[4]:=d1 ;bonus[5]:=e1 ;bonus[6]:=f1;
  33.   bonus[7]:=g1 ;bonus[8]:=h1 ;bonus[9]:=i1 ;bonus[10]:=j1;bonus[11]:=k1;bonus[12]:=l1;
  34.   bonus[13]:=m1;bonus[14]:=nn1;bonus[15]:=o1;bonus[16]:=p1;bonus[17]:=q1;bonus[18]:=r1;
  35.   bonus[19]:=ss1;bonus[20]:=t1;bonus[21]:=u1;bonus[22]:=v1;bonus[23]:=w1;bonus[24]:=x1;
  36.   bonus[25]:=y1;bonus[26]:=z1;
  37.   cost[1]:=a2; cost[2]:=b2;cost[3]:=c2;cost[4]:=d2;cost[5]:=e2;cost[6]:=f2;
  38.   cost[7]:=g2; cost[8]:=h2;cost[9]:=i2;cost[10]:=j2;cost[11]:=k2;cost[12]:=l2;
  39.   cost[13]:=m2; cost[14]:=n2;cost[15]:=o2;cost[16]:=p2;cost[17]:=q2;cost[18]:=r2;
  40.   cost[19]:=s2; cost[20]:=t2;cost[21]:=u2;cost[22]:=v2;cost[23]:=w2;cost[24]:=x2;
  41.   cost[25]:=y2; cost[26]:=z2;
  42.   recurs(s[1],1);
  43.   writeln(n1);
  44.   writeln(s1);
  45. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement