Форум по Delphi программированию

Delphi Sources



Вернуться   Форум по Delphi программированию > Все о Delphi > [ "Начинающим" ] > Код на шару!
Ник
Пароль
Регистрация <<         Правила форума         >> FAQ Пользователи Календарь Поиск Сообщения за сегодня Все разделы прочитаны

Ответ
 
Опции темы Поиск в этой теме Опции просмотра
  #1  
Старый 15.12.2012, 13:05
Dmitry_DM Dmitry_DM вне форума
Активный
 
Регистрация: 07.08.2012
Сообщения: 258
Версия Delphi: Delphi 7
Репутация: 11
По умолчанию Помогите, если можете!

Вот тут задал вопрос http://www.delphisources.ru/forum/sh...ad.php?t=22936
Решите хоть какую-то задачу, пожалуйста!!
Ответить с цитированием
  #2  
Старый 15.12.2012, 15:35
Аватар для YVitaliy
YVitaliy YVitaliy вне форума
Местный
 
Регистрация: 14.12.2011
Сообщения: 481
Версия Delphi: Borland Delphi7
Репутация: 17
По умолчанию

А зачем тебе это? Обычные прикладные задачки. Каждый решит такую по-своему, в зависимости от личного стиля программирования.

Вот мое решение 3й задачки:
Код:
program Project1;

{$APPTYPE CONSOLE}

uses SysUtils;
  type OneCompt=record
   start, finish:integer;
   n_i:array of integer;
  end;
  type
  comptArray=array of OneCompt;

var
  res:integer;
  ccount:Integer;
  i, dd, hh, mm:Integer;
  s, s1:string;
  compts:comptArray;
  f:TextFile;
  function max(const a, b:integer):integer;
  begin
    if a>b then result:=a else result:=b;
  end;

  procedure ComptSort(var A: comptArray; sLo, sHi: Integer);
  var
    Lo, Hi, Md: Integer;
    T:OneCompt;
  begin
    Lo := sLo;
    Hi := sHi;
    Md := compts[(Lo + Hi) div 2].start;
    repeat
      while A[Lo].start < Md do Inc(Lo);
      while A[Hi].start > Md do Dec(Hi);
      if Lo <= Hi then
      begin
        T := compts[Lo];
        A[Lo] := A[Hi];
        A[Hi] := T;
        Inc(Lo);
        Dec(Hi);
      end;
    until Lo > Hi;
    if Hi > sLo then ComptSort(A, sLo, Hi);
    if Lo < sHi then ComptSort(A, Lo, sHi);
  end;

  procedure getNI(var A: comptArray);
  var
    i,j:integer;
  begin
    for i:=0 to high(A) do
     begin
       for j:=i+1 to high(A) do
        begin
           if A[j].Start>=A[i].Finish then
            begin
              setlength(A[i].n_i, length(A[i].n_i)+1);
              A[i].n_i[high(A[i].n_i)]:=j;
            end;
        end;
     end;
  end;
  
  Function GetComptCount(const A:comptArray; const st:integer):integer;
  var
     i:Integer;
     rc:integer;
  begin
   result:=0;
   if st>high(a) then
     exit;
     rc:=0;
     for i:=0 to high(A[st].n_i) do
      begin
        rc:=max(rc, GetComptCount(A,A[st].n_i[i]));
      end;
   result:=rc + 1;
  end;
begin
  AssignFile(f,'input.txt');
  Reset(f);
  Readln(F, ccount);
  SetLength(compts,ccount);
  for i:=0 to ccount-1 do
   begin
      Readln(F, s);
      s1:=copy(s,1,2);
      hh:=strtoint(s1);
      s1:=copy(s,4,2);
      mm:=strtoint(s1);
      compts[i].start:=hh*60 + mm;
      s1:=copy(s,7,2);
      hh:=strtoint(s1);
      s1:=copy(s,10,2);
      mm:=strtoint(s1);
      compts[i].finish:=hh*60 + mm;
      s1:=copy(s, 13,2);
      dd:=strtoint(s1);
      compts[i].start:=compts[i].start + dd*24*60;
      compts[i].finish:=compts[i].finish + dd*24*60;
   end;
   
   ComptSort(compts, 0, ccount-1);
   getNI(compts);
   res:=0;
    for i:=0 to ccount-1 do
     res:=max(res, GetComptCount(compts, i));
     writeln(res);
   readln;
end.
Ответить с цитированием
Этот пользователь сказал Спасибо YVitaliy за это полезное сообщение:
Dmitry_DM (15.12.2012)
  #3  
Старый 15.12.2012, 19:07
Dmitry_DM Dmitry_DM вне форума
Активный
 
Регистрация: 07.08.2012
Сообщения: 258
Версия Delphi: Delphi 7
Репутация: 11
По умолчанию

Цитата:
Сообщение от YVitaliy
А зачем тебе это? Обычные прикладные задачки. Каждый решит такую по-своему, в зависимости от личного стиля программирования.

Вот мое решение 3й задачки:
Код:
program Project1;

{$APPTYPE CONSOLE}

uses SysUtils;
  type OneCompt=record
   start, finish:integer;
   n_i:array of integer;
  end;
  type
  comptArray=array of OneCompt;

var
  res:integer;
  ccount:Integer;
  i, dd, hh, mm:Integer;
  s, s1:string;
  compts:comptArray;
  f:TextFile;
  function max(const a, b:integer):integer;
  begin
    if a>b then result:=a else result:=b;
  end;

  procedure ComptSort(var A: comptArray; sLo, sHi: Integer);
  var
    Lo, Hi, Md: Integer;
    T:OneCompt;
  begin
    Lo := sLo;
    Hi := sHi;
    Md := compts[(Lo + Hi) div 2].start;
    repeat
      while A[Lo].start < Md do Inc(Lo);
      while A[Hi].start > Md do Dec(Hi);
      if Lo <= Hi then
      begin
        T := compts[Lo];
        A[Lo] := A[Hi];
        A[Hi] := T;
        Inc(Lo);
        Dec(Hi);
      end;
    until Lo > Hi;
    if Hi > sLo then ComptSort(A, sLo, Hi);
    if Lo < sHi then ComptSort(A, Lo, sHi);
  end;

  procedure getNI(var A: comptArray);
  var
    i,j:integer;
  begin
    for i:=0 to high(A) do
     begin
       for j:=i+1 to high(A) do
        begin
           if A[j].Start>=A[i].Finish then
            begin
              setlength(A[i].n_i, length(A[i].n_i)+1);
              A[i].n_i[high(A[i].n_i)]:=j;
            end;
        end;
     end;
  end;
  
  Function GetComptCount(const A:comptArray; const st:integer):integer;
  var
     i:Integer;
     rc:integer;
  begin
   result:=0;
   if st>high(a) then
     exit;
     rc:=0;
     for i:=0 to high(A[st].n_i) do
      begin
        rc:=max(rc, GetComptCount(A,A[st].n_i[i]));
      end;
   result:=rc + 1;
  end;
begin
  AssignFile(f,'input.txt');
  Reset(f);
  Readln(F, ccount);
  SetLength(compts,ccount);
  for i:=0 to ccount-1 do
   begin
      Readln(F, s);
      s1:=copy(s,1,2);
      hh:=strtoint(s1);
      s1:=copy(s,4,2);
      mm:=strtoint(s1);
      compts[i].start:=hh*60 + mm;
      s1:=copy(s,7,2);
      hh:=strtoint(s1);
      s1:=copy(s,10,2);
      mm:=strtoint(s1);
      compts[i].finish:=hh*60 + mm;
      s1:=copy(s, 13,2);
      dd:=strtoint(s1);
      compts[i].start:=compts[i].start + dd*24*60;
      compts[i].finish:=compts[i].finish + dd*24*60;
   end;
   
   ComptSort(compts, 0, ccount-1);
   getNI(compts);
   res:=0;
    for i:=0 to ccount-1 do
     res:=max(res, GetComptCount(compts, i));
     writeln(res);
   readln;
end.
Спасибо огромное!!
Ответить с цитированием
Ответ


Delphi Sources

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать темы
Вы не можете отвечать на сообщения
Вы не можете прикреплять файлы
Вы не можете редактировать сообщения

BB-коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход


Часовой пояс GMT +3, время: 08:42.


 

Сайт

Форум

FAQ

RSS лента

Прочее

 

Copyright © Форум "Delphi Sources" by BrokenByte Software, 2004-2023

ВКонтакте   Facebook   Twitter