Pages

Rabu, 17 April 2013

Pembahasan Soal Sphere Online Judge problem No.11

Hallo para sobat blogger, khususnya para programmer pemula.

Kali ini saya akan membahas soal pemrograman dari situs web Sphere Online Judge problem nomor 11. 

Silahkan diterjemahkan sendiri soalnya ini.


The most important part of a GSM network is so called Base Transceiver Station (BTS). These transceivers form the areas called cells (this term gave the name to the cellular phone) and every phone connects to the BTS with the strongest signal (in a little simplified view). Of course, BTSes need some attention and technicians need to check their function periodically.
ACM technicians faced a very interesting problem recently. Given a set of BTSes to visit, they needed to find the shortest path to visit all of the given points and return back to the central company building. Programmers have spent several months studying this problem but with no results. They were unable to find the

Sabtu, 05 Januari 2013

BAB 1D : Fungsi dan Prosedur - Procedure

Solusi BAB 1D : Fungsi dan Prosedur - Procedure




PROGRAM prosedur;
var
    bil : integer;
procedure TulisJawaban(x: integer);
begin
    case x of
        1..9: begin writeln('satuan'); end;
        10..99: begin writeln('puluhan'); end;
        100..999: begin writeln('ratusan'); end;
        1000..9999: begin writeln('ribuan'); end;
        10000..30000: begin writeln('puluhribuan'); end;
    end;
end;
 
begin
while not eof(input) do
begin
    readln(bil);
    TulisJawaban(bil);
end;
end.

BAB 1D : Fungsi dan Prosedur - Function

Solusi BAB 1D : Fungsi dan Prosedur - Function




PROGRAM fungsi;
var
    bil: integer;
 
function Faktorial(n: integer): longint;
begin
    if (n = 0) then
        Faktorial := 1
    else
        Faktorial := n * Faktorial (n - 1);
end;
 
function Valid(n: integer): boolean;
begin
    Valid := (n >= 0) and (n <= 10);
end;
 
begin
    readln(bil);
    if (Valid(bil)) then
        writeln(Faktorial(bil))
    else
        writeln('ditolak');
end.

BAB 1D : Fungsi dan Prosedur - Var Parameter

Solusi BAB 1D : Fungsi dan Prosedur - Var Parameter




PROGRAM varparameter;
var
    a, b: integer;
 
 
procedure Swap(var a, b: integer);
var
    temp: integer;
begin
    temp := a;
    a := b;
    b := temp;
end;
 
 
begin
    readln(a, b);
    Swap(a, b);
    writeln(a, ' ', b);
end.

BAB 1C : Perulangan - Bilangan Agak Prima

Solusi BAB 1C : Perulangan - Bilangan Agak Prima




PROGRAM agakprima;
var pr,bts,tes,cek : longint;
    c,a : byte;
begin
     readln(c);
     for a:=1 to c do
         begin
              readln(pr);
              cek:=0;
              tes:=3;
              bts:=trunc(pr/2);
     if ((pr mod 2=0) and (pr<>2)) or (pr=1) then
        inc(cek);
     while tes<=bts do
     begin
       if (pr mod tes=0) then
       begin
        inc(cek);
        if cek>2 then break;
       end;
       inc(tes);
     end;
     if cek>2 then
       writeln('TIDAK')
     else
       writeln('YA');
     end;
end.

BAB 1C : Perulangan - Faktor Bilangan

Solusi BAB 1C : Perulangan - Faktor Bilangan




PROGRAM faktorbilangan;
var N,i:longint;
begin
readln(N);
for i:=1 to N do begin
 if N mod i=0 then begin
  writeln(N/i:0:0);
 end;
end;
 
readln end.