编辑代码

Program StockMarketAnalysis;
type
  PriceInfo =Record
     Minute :Integer;
     Price :Integer;
  end;
type
   OutPrcieInfo =Record
     Minute :Integer;
     CurrentMaxPrice :Integer;
     CurrentMinPrice :Integer;
     MinPrice :Integer;
  end;
var
  vNum, i, j, vTotalMinute :Integer;
  Prices :array of PriceInfo;
  vOutPrices :array of OutPrcieInfo;
  vCurrentMinute, vCurrentMaxPrice, vCurrentMinPrice, vMinPrice :Integer;
begin
  //输入价格信息的个数
  Writeln('输入N:  ') ; 
  Readln(vNum);
  SetLength(Prices, vNum);
  for i :=0 to vNum - 1 do
  begin
    Writeln('输入第:  ' ,(i+1),' 个价格信息(分钟 价格):') ; 
    Readln(Prices[i].Minute, Prices[i].Price);
  end;
  vTotalMinute :=Prices[vNum - 1].Minute;
  SetLength(vOutPrices, vTotalMinute);
  //按照分钟值从小到大排序
  for i :=1 to vTotalMinute do 
  begin
     vOutPrices[i-1].Minute := i;
     //获取当前分钟数最大值最小值
     vCurrentMaxPrice :=0;
     vCurrentMinPrice :=0;
     for j:=0 to vNum -1 do
     begin
        if Prices[j].Minute = i then
        begin
           if Prices[j].Price >vCurrentMaxPrice then
             vCurrentMaxPrice :=Prices[j].Price;
           if vCurrentMinPrice = 0 then
             vCurrentMinPrice :=Prices[j].Price
           else if Prices[j].Price < vCurrentMinPrice then  
             vCurrentMinPrice :=Prices[j].Price;    
        end
        else if Prices[j].Minute > i then
        begin
          Break;
        end;
     end;
     vOutPrices[i -1].CurrentMaxPrice := vCurrentMaxPrice;
     vOutPrices[i -1].CurrentMinPrice := vCurrentMinPrice;
     if i>=3 then
     begin
       vMinPrice :=vOutPrices[i -3].CurrentMinPrice;
       if vOutPrices[i -2].CurrentMinPrice < vMinPrice then
         vMinPrice :=vOutPrices[i -2].CurrentMinPrice;
       if vOutPrices[i -1].CurrentMinPrice < vMinPrice then 
         vMinPrice :=vOutPrices[i -1].CurrentMinPrice;
       vOutPrices[i -1].MinPrice := vMinPrice;  
     end;
  end; 
  //判断每分钟是否存在行情拉升
  for i :=1 to vTotalMinute do 
  begin
    if vOutPrices[i -1].Minute <=2 then
       writeln(i, ' N')
    else
    begin
      if (vOutPrices[i].CurrentMaxPrice - vOutPrices[i].MinPrice) >=5 then
         writeln(i, ' Y')
      else
         writeln(i, ' N');   
    end;
  end;
end.