Advertisement
Guest User

Untitled

a guest
Oct 17th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.57 KB | None | 0 0
  1. program kewin;
  2. {uses crt;}
  3. var
  4.   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: integer;
  5.   s,s1 : string;
  6.   bonus: array[1..26] of integer;
  7.   cost : array[1..26] of integer;
  8.  
  9.  {Їа®жҐ¤га  ўлўҐ¤Ґ­Ёп бва®ЄЁ Ё ҐҐ "бв®Ё¬®бвЁ"
  10.   + § Ї®¬Ё­ Ґ¬ бва®Єг Ё бв®Ё¬®бвм, Ґб«Ё ®­  ¬Ґ­миҐ а ­ҐҐ ­ ©¤Ґ­­ле}
  11. procedure output(par:string);
  12. var sum, i:integer;
  13. begin
  14.   sum:=0;
  15.   for i := 1 to length(par) do
  16.    sum:=sum + cost[ord(par[i])-96];
  17.   {writeln ('‚ аЁ ­в :',par,' - ',sum);}
  18.   {Ґб«Ё ¬Ё­Ё¬г¬ - § Ї®­Ё¬}
  19.   if n1 < 0  then begin n1:=sum; s1:=par; end;
  20.   if sum< n1 then begin n1:=sum; s1:=par; end;
  21. end;
  22.  
  23.  {४габЁп! б¬лб« ў ⮬ ,зв® Є ⥪г饩 бва®ЄЁ ¬®¦­® ¤®Ў ўЁвм
  24.  б«Ґ¤гойЁ© бЁ¬ў®« Ё§ S ,  ¬®¦­® ЇҐаҐи Ј­гвм ­  ¤®ЇгбвЁ¬®Ґ §­ зҐ­ЁҐ
  25.  Ё в Є ¤ «ҐҐ ,Ї®Є  ­Ґ гЇаҐ¬бп ў Є®­Ґж бва®ЄЁ}
  26. procedure recurs(str:string;  pos:integer);
  27.  var    i:integer;
  28. begin
  29.    for i := 1 to  bonus[ord(str[length(str)])-96]+1
  30.     do
  31.      if pos+i >= n  then
  32.      output(str+s[n])
  33.      else
  34.      recurs(str+s[pos+i],pos+i);
  35. end;
  36.  
  37. begin
  38. {clrscr;}
  39.   n1 := -1;
  40.    {write('n=');} readln(n);
  41.    {write('s=');} readln(s);
  42.  
  43.   n:=8;
  44.   s:='abcdebha';
  45.  
  46.     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);
  47.      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);
  48.   bonus[1]:=a1 ;bonus[2]:=b1 ;bonus[3]:=c1 ;bonus[4]:=d1 ;bonus[5]:=e1 ;bonus[6]:=f1;
  49.   bonus[7]:=g1 ;bonus[8]:=h1 ;bonus[9]:=i1 ;bonus[10]:=j1;bonus[11]:=k1;bonus[12]:=l1;
  50.   bonus[13]:=m1;bonus[14]:=nn1;bonus[15]:=o1;bonus[16]:=p1;bonus[17]:=q1;bonus[18]:=r1;
  51.   bonus[19]:=ss1;bonus[20]:=t1;bonus[21]:=u1;bonus[22]:=v1;bonus[23]:=w1;bonus[24]:=x1;
  52.   bonus[25]:=y1;bonus[26]:=z1;
  53.   cost[1]:=a2; cost[2]:=b2;cost[3]:=c2;cost[4]:=d2;cost[5]:=e2;cost[6]:=f2;
  54.   cost[7]:=g2; cost[8]:=h2;cost[9]:=i2;cost[10]:=j2;cost[11]:=k2;cost[12]:=l2;
  55.   cost[13]:=m2; cost[14]:=n2;cost[15]:=o2;cost[16]:=p2;cost[17]:=q2;cost[18]:=r2;
  56.   cost[19]:=s2; cost[20]:=t2;cost[21]:=u2;cost[22]:=v2;cost[23]:=w2;cost[24]:=x2;
  57.   cost[25]:=y2; cost[26]:=z2;
  58.  
  59.   {‘в ав®ў п Ї®§ЁжЁп}
  60.   recurs(s[1],1);
  61.   {writeln;
  62.   writeln('ЋЇвЁ¬ «м­л© ў аЁ ­в: ',s1,' - ',n1);}
  63.   writeln(n1);
  64.   {repeat until keypressed;}
  65. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement