# просчитайте количество целых чисель от L до R все цифры которых различный # Код на ruby 2.2.3p173 def allDifferentNumbers?(n) a = [] while n > 0 do return false if a.include?(n % 10) a << n % 10 n = n / 10 end return true end
def zadanie(l, r) k = 0 for i in l..r k += 1 if allDifferentNumbers?(i) end return k end
function DifNum(a: integer): integer; var se: set of integer; i: integer; begin while a > 0 do begin if a mod 10 in se then begin DifNum := 0; exit; end else include(se, a mod 10); a := a div 10; end; DifNum := 1; end;
begin read(l, r); for i := l to r do counter += DifNum(i); writeln(counter); end.
//Альтернативное решение на Паскале
Var l,r:integer; begin read(l,r); writeln(range(l,r).where(x -> x.tostring.toarray.distinct.count=length(x.tostring)).Count); end.
# Код на ruby 2.2.3p173
def allDifferentNumbers?(n)
a = []
while n > 0 do
return false if a.include?(n % 10)
a << n % 10
n = n / 10
end
return true
end
def zadanie(l, r)
k = 0
for i in l..r
k += 1 if allDifferentNumbers?(i)
end
return k
end
# Примеры применения
p zadanie(11, 13)
var
l, r, counter, i: integer;
function DifNum(a: integer): integer;
var se: set of integer;
i: integer;
begin
while a > 0 do
begin
if a mod 10 in se then
begin
DifNum := 0;
exit;
end
else include(se, a mod 10);
a := a div 10;
end;
DifNum := 1;
end;
begin
read(l, r);
for i := l to r do
counter += DifNum(i);
writeln(counter);
end.
//Альтернативное решение на Паскале
Var
l,r:integer;
begin
read(l,r);
writeln(range(l,r).where(x -> x.tostring.toarray.distinct.count=length(x.tostring)).Count);
end.
//Dev-C++ 5.11 (C)
#include <stdio.h>
#include <malloc.h>
int DifNum(int);
int main(void)
{int l,r,counter=0;
scanf("%d %d",&l,&r);
for(int i=l;i<=r;i++)
counter+=DifNum(i);
printf("%d",counter);
return 0;}
int DifNum(int a)
{int k=1,*nums;
nums=(int*)malloc(k*sizeof(int));
nums[0]=-1;
while(a>0)
{for(int i=0;i<k;i++)
if(a%10==nums[i])
return 0;
k++;
nums=(int*)malloc(k*sizeof(int));
nums[k-1]=a%10;
a/=10;}
free(nums);
return 1;}
Пример ввода:
1 12
Пример вывода:
11