10 Tin 2k11 - THPT Chuyên Lương Thế Vinh Đồng Nai Data Structures + Algorithms = Programming Saturday, 20-04-24, 1:42 AM
[ New messages · Members · Forum rules · Search · RSS ]
  • Page 1 of 1
  • 1
Forum moderator: comet  
Forum » Thuật Toán » Thuật Toán » bài tâp xuat ra so 4 chữ số có thứ tự tăng dần
bài tâp xuat ra so 4 chữ số có thứ tự tăng dần
hex1105Date: Wednesday, 07-09-11, 10:34 PM | Message # 1
Private
Group: Users
Messages: 7
Reputation: 0
Status: Offline
Code
uses crt;
var a:array[1..10] of longint;
t,i,n:longint;
procedure tachso(n:longint;var a:array of longint;var t:longint);
var i,dv,j:longint;
begin
   i:=1; t:=0;
   while n<>0 do
    begin
     dv:=n mod 10;
     a[i]:=dv;
     i:=i+1;
     n:=n div 10;
     t:=t+1;
    end;
end;
{-----}
function kiemtra(var t:longint;var a:array of longint):boolean;
var i,j,tam:longint;
begin
kiemtra:=true;
for i:=1 to t do
   begin
    for j:=i+1 to t do
     if a[i]>a[j] then
      begin
       tam:=a[i];
       a[i]:=a[j];
       a[j]:=tam;
       end;
      end;
for i:=1 to t-1 do
   if a[i+1]-a[i]<>1 then
    begin
     kiemtra:=false;
     break;
    end;
end;
{-------}
begin
clrscr;
n:=0;
for i:=1 to 9999 do
   begin
    tachso(i,a,t);
    if kiemtra(t,a)=true then
     begin
      write(i:5);
      n:=n+1;
      if n mod 10 = 0 then writeln();
     end;
    end;
readln;
end.


Message edited by hex1105 - Thursday, 08-09-11, 7:40 PM
 
kiepmeodoremonDate: Thursday, 08-09-11, 7:33 PM | Message # 2
Major
Group: Users
Messages: 91
Reputation: 0
Status: Offline
B ơi, sao biến f khaj báo mà không thấy dùng z ??

Giàu thì ghét - Đói rét thì khinh - Thông minh thì diệt.
 
hex1105Date: Thursday, 08-09-11, 7:40 PM | Message # 3
Private
Group: Users
Messages: 7
Reputation: 0
Status: Offline
ghi nhầm í mừ
 
nguyenchauthuanDate: Tuesday, 13-09-11, 10:34 PM | Message # 4
Sergeant
Group: Users
Messages: 33
Reputation: 0
Status: Offline
Ế bình ơi, cái vòng for ở thân ct chính cho chạy từ 1000 đi, bớt dc 999 vòng lặp!!!

Rơi
 
Forum » Thuật Toán » Thuật Toán » bài tâp xuat ra so 4 chữ số có thứ tự tăng dần
  • Page 1 of 1
  • 1
Search:

Website builderuCoz!-->
Copyright Hoàng Anh © 2024