Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uses crt;
- var
- st:string;
- n:longint;
- function num(x:char):longint;
- begin
- num:=ord(x)-48;
- end;
- procedure swap(var x,y:char);
- var tmp:char;
- begin
- tmp:=x; x:=y; y:=tmp;
- end;
- function sort(st:string;bool:boolean):longint;
- var i,j:longint;
- begin
- for i:=1 to n do
- for j:=i+1 to n do
- if (num(st[i]) > num(st[j]) = bool) then
- swap(st[i],st[j]);
- val(st,sort);
- end;
- procedure solve();
- var sub,c:longint;
- begin
- c:=0;
- readln(st);
- n:=length(st);
- repeat
- begin
- sub:=sort(st,false)-sort(st,true);
- str(sub,st);
- inc(c);
- end;
- until (sub=6174);
- writeln(c);
- end;
- begin
- clrscr();
- solve();
- readln();
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement