Каждая буква кодирует некоторую цифру.
Задача2: Решить задачу1 на как можно большем языке программирования. Пожалуйста,проверьте что есть(для некоторых языков даже компилятора нет) и предложите реализацию на чем-нибудь еще
C++:
#include <iostream.h>
#include <kmm.rulit>
int main()
{
int r,e,s,i,c,l,n;
for(r=0;r<=9;r++)
for(e=0;e<=9;e++)
if (r!=e)
for(s=0;s<=9;s++)
if ((s!=r) && (s!=e))
for(i=0;i<=9;i++)
if ((i!=s) && (i!=r) && (i!=e))
for(c=0;c<=9;c++)
if ((c!=i) && (c!=s) && (c!=r) && (c!=e))
for(l=0;l<=9;l++)
if ((l!=c) && (l!=i) && (l!=s) && (l!=r) && (l!=e))
for(n=0;n<=9;n++)
if ((n!=l) && (n!=c) && (n!=i) && (n!=s) && (n!=r) && (n!=e))
if((1000*r+100*e+10*s+i+1000*e+100*c+10*l+i)==(10000*c+1000*i+100*l+10*e+n))
cout<<r<<' '<<e<<' '<<s<<' '<<i<<' '<<c<<' '<<l<<' '<<n<<'\n';
cin>>r;
return 0;
}
Pascal:
program MyProg;
uses KMM;
var
r,e,s,i,c,l,n : word;
begin
for r:=0 to 9 do
for e:=0 to 9 do
if (r<>e) then
for s:=0 to 9 do
if ((s<>r) and (s<>e)) then
for i:=0 to 9 do
if ((i<>s) and (i<>r) and (i<>e)) then
for c:=0 to 9 do
if ((c<>i) and (c<>s) and (c<>r) and (c<>e)) then
for l:=0 to 9 do
if ((l<>c) and (l<>i) and (l<>s) and (l<>r) and (l<>e)) then
for n:=0 to 9 do
if ((n<>l) and(n<>c) and (n<>i) and (n<>s) and (n<>r) and (n<>e)) then
if((1000*r+100*e+10*s+i+1000*e+100*c+10*l+i) = (10000*c+1000*i+100*l+10*e+n)) then
WriteLn(r,' ',e,' ',s,' ',i,' ',c,' ',l,' ',n);
readln;
end.
Java:
public class Program {
public static void main(String[] args) {
int r,e,s,i,c,l,n;
for(r=0;r<=9;r++)
for(e=0;e<=9;e++)
if (r!=e)
for(s=0;s<=9;s++)
if ((s!=r) && (s!=e))
for(i=0;i<=9;i++)
if ((i!=s) && (i!=r) && (i!=e))
for(c=0;c<=9;c++)
if ((c!=i) && (c!=s) && (c!=r) && (c!=e))
for(l=0;l<=9;l++)
if ((l!=c) && (l!=i) && (l!=s) && (l!=r) && (l!=e))
for(n=0;n<=9;n++)
if ((n!=l) &&(n!=c) && (n!=i) && (n!=s) && (n!=r) && (n!=e))
if((1000*r+100*e+10*s+i+1000*e+100*c+10*l+i)==(10000*c+1000*i+100*l+10*e+n))
System.out.println(r+" "+e+" "+s+" "+i+" "+c+" "+l+" "+n);//'\n';
}
}
Ada:
with Ada.Text_IO, Ada.Integer_Text_IO;
use Ada.Text_IO, Ada.Integer_Text_IO;
procedure MyProc is
r: Integer := 0;
e: Integer := 0;
s: Integer := 0;
i: Integer := 0;
c: Integer := 0;
l: Integer := 0;
n: Integer := 0;
begin
for r in 0 .. 9
loop
for e in 0 .. 9
loop
if (r<>e) then
for s in 0 .. 9
loop
if ((s<>r) and (s<>e)) then
for i in 0 .. 9
loop
if ((i<>s) and (i<>r) and (i<>e)) then
for c in 0 .. 9
loop
if ((c<>i) and (c<>s) and (c<>r) and (c<>e)) then
for l in 0 .. 9
loop
if ((l<>c) and (l<>i) and (l<>s) and (l<>r) and (l<>e)) then
for n in 0 .. 9
loop
if ((n<>l) and(n<>c) and (n<>i) and (n<>s) and (n<>r) and (n<>e)) then
if((1000*r+100*e+10*s+i+1000*e+100*c+10*l+i) = (10000*c+1000*i+100*l+10*e+n)) then
Write(r,' ',e,' ',s,' ',i,' ',c,' ',l,' ',n);
end if;
end if;
end loop;
end if;
end loop;
end if;
end loop;
end if;
end loop;
end if;
end loop;
end if;
end loop;
end loop;
end MyProc;
PHP:
<?php
$r=0;$e=0;$s=0;$i=0;$c=0;$l=0;$n=0;
for($r=0;$r<=9;$r++)
for($e=0;$e<=9;$e++)
if ($r!=$e)
for($s=0;$s<=9;$s++)
if (($s!=$r) && ($s!=$e))
for($i=0;$i<=9;$i++)
if (($i!=$s) && ($i!=$r) && ($i!=$e))
for($c=0;$c<=9;$c++)
if (($c!=i) && ($c!=$s) && ($c!=$r) && ($c!=$e))
for($l=0;$l<=9;$l++)
if (($l!=$c) && ($l!=$i) && ($l!=$s) && ($l!=$r) && ($l!=$e))
for($n=0;$n<=9;$n++)
if (($n!=l) &&($n!=$c) && ($n!=$i) && ($n!=$s) && ($n!=$r) && ($n!=$e))
if((1000*$r+100*$e+10*$s+$i+1000*$e+100*$c+10*$l+$i)==(10000*$c+1000*$i+100*$l+10*$e+$n))
print $r.' '.$e.' '.$s.' '.$i.' '.$c.' '.$l.' '.$n.'\n';
?>
PERL:
#! /bin/usr/perl
$r=0;$e=0;$s=0;$i=0;$c=0;$l=0;$n=0;
for($r=0;$r<=9;$r++)
for($e=0;$e<=9;$e++)
if ($r!=$e)
for($s=0;$s<=9;$s++)
if (($s!=$r) && ($s!=$e))
for($i=0;$i<=9;$i++)
if (($i!=$s) && ($i!=$r) && ($i!=$e))
for($c=0;$c<=9;$c++)
if (($c!=i) && ($c!=$s) && ($c!=$r) && ($c!=$e))
for($l=0;$l<=9;$l++)
if (($l!=$c) && ($l!=$i) && ($l!=$s) && ($l!=$r) && ($l!=$e))
for($n=0;$n<=9;$n++)
if (($n!=l) &&($n!=$c) && ($n!=$i) && ($n!=$s) && ($n!=$r) && ($n!=$e))
if((1000*$r+100*$e+10*$s+$i+1000*$e+100*$c+10*$l+$i)==(10000*$c+1000*$i+100*$l+10*$e+$n))
print $r,' ',$e.' ',$s,' ',$i,' ',$c,' ',$l,' ',$n,'\n';
COBOL:
$ SET SOURCEFORMAT"FREE"
DATA DIVISION.
WORKING-STORAGE SECTION.
01 r PIC 9 VALUE ZEROS.
01 e PIC 9 VALUE ZEROS.
01 s PIC 9 VALUE ZEROS.
01 i PIC 9 VALUE ZEROS.
01 c PIC 9 VALUE ZEROS.
01 l PIC 9 VALUE ZEROS.
01 n PIC 9 VALUE ZEROS.
01 r1 PIC 99 VALUE ZEROS.
01 r12 PIC 99 VALUE ZEROS.
01 r11 PIC 99 VALUE ZEROS.
01 r12 PIC 99 VALUE ZEROS.
01 r13 PIC 99 VALUE ZEROS.
01 r14 PIC 99 VALUE ZEROS.
01 r21 PIC 99 VALUE ZEROS.
01 r22 PIC 99 VALUE ZEROS.
01 r23 PIC 99 VALUE ZEROS.
01 r24 PIC 99 VALUE ZEROS.
01 r31 PIC 99 VALUE ZEROS.
01 r32 PIC 99 VALUE ZEROS.
01 r33 PIC 99 VALUE ZEROS.
01 r34 PIC 99 VALUE ZEROS.
01 r35 PIC 99 VALUE ZEROS.
PROCEDURE DIVISION.
PERFORM 10 TIMES
ADD r,1 GIVING r
PERFORM 10 TIMES
ADD e,1 GIVING e
IF (r<>e) THEN
PERFORM 10 TIMES
ADD s,1 GIVING s
IF ((s<>r) and (s<>e)) THEN
PERFORM 10 TIMES
ADD i,1 GIVING i
IF ((i<>s) and (i<>r) and (i<>e)) THEN
PERFORM 10 TIMES
ADD c,1 GIVING c
IF ((c<>i) and (c<>s) and (c<>r) and (c<>e)) THEN
PERFORM 10 TIMES
ADD l,1 GIVING l
IF ((l<>c) and (l<>i) and (l<>s) and (l<>r) and (l<>e)) THEN
PERFORM 10 TIMES
ADD n,1 GIVING n
IF ((n<>l) and(n<>c) and (n<>i) and (n<>s) and (n<>r) and (n<>e)) THEN
MULTIPLY r,1000 GIVING r11
MULTIPLY e,100 GIVING r12
MULTIPLY s,10 GIVING r13
MULTIPLY i,1 GIVING r14
MULTIPLY e,1000 GIVING r21
MULTIPLY c,1000 GIVING r22
MULTIPLY l,1000 GIVING r23
MULTIPLY i,1000 GIVING r24
MULTIPLY c,10000 GIVING r31
MULTIPLY i,1000 GIVING r32
MULTIPLY l,100 GIVING r33
MULTIPLY e,10 GIVING r34
MULTIPLY n,1 GIVING r35
ADD r11, r12, r13, r14, r21, r22, r23,r24 GIVING r1
ADD r31, r32, r33, r34, r35 GIVING r2
IF r1 = r2 THEN
DISPLAY r," ",e," ",s," ",i," ",c," ",l," ",n
END-IF
END-IF
END-PERFORM
END-IF
END-PERFORM
END-IF
END-PERFORM
END-IF
END-PERFORM
END-IF
END-PERFORM
END-IF
END-PERFORM
END-PERFORM
STOP RUN.
Python:
$ pyton
Python 2.3+
int r,e,s,i,c,l,n;
while r<=9:
r++
while e<=9:
e++
if (r!=e):
while s<=9:
s++
if ((s!=r) && (s!=e)):
while i<=9:
i++
if ((i!=s) && (i!=r) && (i!=e)):
while c<=9:
c++
if ((c!=i) && (c!=s) && (c!=r) && (c!=e)):
while l<=9:
l++
if ((l!=c) && (l!=i) && (l!=s) && (l!=r) && (l!=e)):
while n<=9:
if ((n!=l) &&(n!=c) && (n!=i) && (n!=s) && (n!=r) && (n!=e)):
if((1000*r+100*e+10*s+i+1000*e+100*c+10*l+i)==(10000*c+1000*i+100*l+10*e+n)): >>>Print r,' ',e,' ',s,' ',i,' ',c,' ',l,' ',n;
Fortran:
INTEGER r,e,s,i,c,l,n
DO 100 r=0,9
DO 101 e=0,9
IF (r<>e) THEN
DO 102 s=0,9
IF ((s<>r) AND (s<>e)) THEN
DO 103 i=0,9
IF ((i<>s) AND (i<>r) AND (i<>e)) THEN
DO 104 c=0,9
IF ((c<>i) AND (c<>s) AND (c<>r) AND (c<>e)) THEN
DO 105 l=0,9
IF ((l<>c) AND (l<>i) AND (l<>s) AND (l<>r) AND (l<>e)) THEN
DO 106 n=0,9
IF ((n<>l) AND(n<>c) AND (n<>i) AND (n<>s) AND (n<>r) AND (n<>e)) THEN
IF((1000*r+100*e+10*s+i+1000*e+100*c+10*l+i) = (10000*c+1000*i+100*l+10*e+n)) THEN
WRITE(*,' ',*,' ',*,' ',*,' ',*,' ',*,' ',*)r,e,s,i,c,l,n
END IF
END IF
106 CONTINUE
END IF
105 CONTINUE
END IF
104 CONTINUE
END IF
103 CONTINUE
END IF
102 CONTINUE
END IF
101 CONTINUE
100 CONTINUE
END