diff --git a/Configuration/GlobalAssemblyInfo.cs b/Configuration/GlobalAssemblyInfo.cs index 85e277a55..bbb2b2237 100644 --- a/Configuration/GlobalAssemblyInfo.cs +++ b/Configuration/GlobalAssemblyInfo.cs @@ -15,7 +15,7 @@ internal static class RevisionClass public const string Major = "3"; public const string Minor = "8"; public const string Build = "3"; - public const string Revision = "3171"; + public const string Revision = "3173"; public const string MainVersion = Major + "." + Minor; public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision; diff --git a/Configuration/Version.defs b/Configuration/Version.defs index f3d507744..f8712c616 100644 --- a/Configuration/Version.defs +++ b/Configuration/Version.defs @@ -1,4 +1,4 @@ %MINOR%=8 -%REVISION%=3171 +%REVISION%=3173 %COREVERSION%=3 %MAJOR%=3 diff --git a/Release/pabcversion.txt b/Release/pabcversion.txt index b8016aeff..d82246854 100644 --- a/Release/pabcversion.txt +++ b/Release/pabcversion.txt @@ -1 +1 @@ -3.8.3.3171 +3.8.3.3173 diff --git a/ReleaseGenerators/PascalABCNET_version.nsh b/ReleaseGenerators/PascalABCNET_version.nsh index 82936a46a..937819845 100644 --- a/ReleaseGenerators/PascalABCNET_version.nsh +++ b/ReleaseGenerators/PascalABCNET_version.nsh @@ -1 +1 @@ -!define VERSION '3.8.3.3171' +!define VERSION '3.8.3.3173' diff --git a/TestSuite/CompilationSamples/Drawman.pas b/TestSuite/CompilationSamples/Drawman.pas index 8aba5acdd..1a923dccb 100644 --- a/TestSuite/CompilationSamples/Drawman.pas +++ b/TestSuite/CompilationSamples/Drawman.pas @@ -55,7 +55,7 @@ procedure __FinalizeModule__; implementation -uses DMTaskMaker,DMZadan,DrawmanField; +uses DMTaskMaker,DMZadan,DrawManField; procedure SetDrawmanWidth(w: integer); begin diff --git a/TestSuite/CompilationSamples/GraphABC.pas b/TestSuite/CompilationSamples/GraphABC.pas index 818d14a47..e2492d330 100644 --- a/TestSuite/CompilationSamples/GraphABC.pas +++ b/TestSuite/CompilationSamples/GraphABC.pas @@ -2051,7 +2051,8 @@ end; procedure Picture.CopyRect(dst: System.Drawing.Rectangle; bmp: Bitmap; src: System.Drawing.Rectangle); begin // Copy src portion of bmp on dst rectangle of this picture - var tempbmp := GetView(bmp, src); + //var tempbmp := GetView(bmp, src); // SSM 17/09/22 заменил это сложное - не работает под Linux + var tempbmp := bmp.Clone(src,bmp.PixelFormat); // gb.DrawImage(bmp,dst,src,GraphicsUnit.Pixel); gb.DrawImage(tempbmp, dst); tempbmp.Dispose; diff --git a/TestSuite/CompilationSamples/PABCSystem.pas b/TestSuite/CompilationSamples/PABCSystem.pas index 824ea19b6..2b305d171 100644 --- a/TestSuite/CompilationSamples/PABCSystem.pas +++ b/TestSuite/CompilationSamples/PABCSystem.pas @@ -2310,9 +2310,13 @@ function Arr(a: CharRange): array of char; /// Возвращает массив размера n, заполненный случайными целыми значениями function ArrRandom(n: integer := 10; a: integer := 0; b: integer := 100): array of integer; /// Возвращает массив размера n, заполненный случайными целыми значениями -function ArrRandomInteger(n: integer := 10; a: integer := 0; b: integer := 100): array of integer; +function ArrRandomInteger(n: integer; a: integer; b: integer): array of integer; +/// Возвращает массив размера n, заполненный случайными целыми значениями +function ArrRandomInteger(n: integer := 10): array of integer; /// Возвращает массив размера n, заполненный случайными вещественными значениями -function ArrRandomReal(n: integer := 10; a: real := 0; b: real := 10): array of real; +function ArrRandomReal(n: integer; a: real; b: real): array of real; +/// Возвращает массив размера n, заполненный случайными вещественными значениями +function ArrRandomReal(n: integer := 10): array of real; /// Возвращает массив из count элементов, заполненных значениями gen(i) function ArrGen(count: integer; gen: integer->T): array of T; /// Возвращает массив из count элементов, заполненных значениями gen(i), начиная с i=from @@ -2381,22 +2385,22 @@ function MatrByCol(a: sequence of sequence of T): array [,] of T; /// Генерирует двумерный массив по столбцам из последовательности function MatrByCol(m,n: integer; a: sequence of T): array [,] of T; +/// Возвращает матрицу m на n целых, введенных с клавиатуры +function ReadMatrInteger(m, n: integer): array [,] of integer; +/// Возвращает матрицу m на n вещественных, введенных с клавиатуры +function ReadMatrReal(m, n: integer): array [,] of real; /// Возвращает двумерный массив размера m x n, заполненный случайными целыми значениями function MatrRandom(m: integer := 5; n: integer := 5; a: integer := 0; b: integer := 100): array [,] of integer; /// Возвращает двумерный массив размера m x n, заполненный случайными целыми значениями function MatrRandomInteger(m: integer := 5; n: integer := 5; a: integer := 0; b: integer := 100): array [,] of integer; /// Возвращает двумерный массив размера m x n, заполненный случайными вещественными значениями function MatrRandomReal(m: integer := 5; n: integer := 5; a: real := 0; b: real := 10): array [,] of real; -/// Возвращает двумерный массив размера m x n, заполненный элементами x -function MatrFill(m, n: integer; x: T): array [,] of T; /// Возвращает двумерный массив размера m x n, заполненный элементами gen(i,j) function MatrGen(m, n: integer; gen: (integer,integer)->T): array [,] of T; +/// Возвращает двумерный массив размера m x n, заполненный элементами x +function MatrFill(m, n: integer; x: T): array [,] of T; /// Транспонирует двумерный массив function Transpose(a: array [,] of T): array [,] of T; -/// Возвращает матрицу m на n целых, введенных с клавиатуры -function ReadMatrInteger(m, n: integer): array [,] of integer; -/// Возвращает матрицу m на n вещественных, введенных с клавиатуры -function ReadMatrReal(m, n: integer): array [,] of real; // ----------------------------------------------------- //>> Подпрограммы для создания кортежей # Subroutines for tuple generation @@ -4782,6 +4786,8 @@ begin Result := ArrRandom(n, a, b); end; +function ArrRandomInteger(n: integer) := ArrRandomInteger(n,0,100); + function ArrRandomReal(n: integer; a: real; b: real): array of real; begin Result := new real[n]; @@ -4789,6 +4795,8 @@ begin Result[i] := Random() * (b - a) + a; end; +function ArrRandomReal(n: integer) := ArrRandomReal(n,0,10); + function SeqRandom(n: integer; a: integer; b: integer): sequence of integer; begin loop n do @@ -12145,12 +12153,29 @@ begin end; end; -/// Возвращает n-тую декартову степень множества элементов, заданного массивом +/// Возвращает n-тую декартову степень множества элементов, заданного последовательностью function Cartesian(Self: sequence of T; n: integer): sequence of array of T; extensionmethod; begin Result := Self.ToArray.Cartesian(n); end; +/// Возвращает все перестановки букв в строке в виде последовательности строк +function Permutations(Self: string): sequence of string; extensionmethod +:= Self.ToCharArray.Permutations.Select(p -> new string(p)); + +/// Возвращает все частичные перестановки букв строки по m символов в виде последовательности строк +function Permutations(Self: string; m: integer): sequence of string; extensionmethod +:= Self.ToCharArray.Permutations(m).Select(p -> new string(p)); + +/// Возвращает n-тую декартову степень множества символов, заданного строкой +function Cartesian(Self: string; n: integer): sequence of string; extensionmethod +:= Self.ToCharArray.Cartesian(n).Select(p -> new string(p)); + +/// Возвращает все сочетания по m элементов +function Combinations(Self: string; m: integer): sequence of string; extensionmethod +:= Self.ToCharArray.Combinations(m).Select(p -> new string(p)); + + // Внутренние функции для одномерных массивов ///-- diff --git a/TestSuite/CompilationSamples/School.pas b/TestSuite/CompilationSamples/School.pas index ad6d8b2fa..b85f24066 100644 --- a/TestSuite/CompilationSamples/School.pas +++ b/TestSuite/CompilationSamples/School.pas @@ -964,22 +964,6 @@ end; procedure SwapSubstr(var Self: string; ss1, ss2: string); extensionmethod := SwapSubstr(Self, ss1, ss2); -/// Возвращает все перестановки букв в строке в виде последовательности строк -function Permutations(Self: string): sequence of string; extensionmethod -:= Self.ToCharArray.Permutations.Select(p -> new string(p)); - -/// Возвращает все частичные перестановки букв строки по m символов в виде последовательности строк -function Permutations(Self: string; m: integer): sequence of string; extensionmethod -:= Self.ToCharArray.Permutations(m).Select(p -> new string(p)); - -/// Возвращает n-тую декартову степень множества символов, заданного строкой -function Cartesian(Self: string; n: integer): sequence of string; extensionmethod -:= Self.ToCharArray.Cartesian(n).Select(p -> new string(p)); - -/// Возвращает все сочетания по m элементов -function Combinations(Self: string; m: integer): sequence of string; extensionmethod -:= Self.ToCharArray.Combinations(m).Select(p -> new string(p)); - {$endregion} begin diff --git a/_GenerateLinuxVersion.bat b/_GenerateLinuxVersion.bat index 40e8c57a2..fb3a4196d 100644 --- a/_GenerateLinuxVersion.bat +++ b/_GenerateLinuxVersion.bat @@ -1,3 +1,13 @@ +rmdir Release\Samples\ /s /q +rmdir Release\PascalABCNETLinux\ /s /q +mkdir Release\PascalABCNETLinux\ +mkdir Release\PascalABCNETLinux\Lib\ +mkdir Release\PascalABCNETLinux\Lng\Rus +mkdir Release\PascalABCNETLinux\Lng\Eng +mkdir Release\PascalABCNETLinux\Highlighting\ +del Release\PascalABCNETLinux.zip + + copy bin\CodeCompletion.dll Release\PascalABCNETLinux\CodeCompletion.dll copy bin\Compiler.dll Release\PascalABCNETLinux\Compiler.dll copy bin\CompilerTools.dll Release\PascalABCNETLinux\CompilerTools.dll @@ -65,10 +75,12 @@ copy bin\Lib\FilesOperations.pas Release\PascalABCNETLinux\Lib\FilesOperations.p copy bin\Lib\FilesOperations.pcu Release\PascalABCNETLinux\Lib\FilesOperations.pcu copy bin\Lib\FormsABC.pas Release\PascalABCNETLinux\Lib\FormsABC.pas copy bin\Lib\FormsABC.pcu Release\PascalABCNETLinux\Lib\FormsABC.pcu +copy bin\Lib\GraphABC.pas Release\PascalABCNETLinux\Lib\GraphABC.pas copy bin\Lib\GraphABC.pcu Release\PascalABCNETLinux\Lib\GraphABC.pcu +copy bin\Lib\ABCObjects.pas Release\PascalABCNETLinux\Lib\ABCObjects.pas +copy bin\Lib\ABCObjects.pcu Release\PascalABCNETLinux\Lib\ABCObjects.pcu +copy bin\Lib\GraphABCHelper.pas Release\PascalABCNETLinux\Lib\GraphABCHelper.pas copy bin\Lib\GraphABCHelper.pcu Release\PascalABCNETLinux\Lib\GraphABCHelper.pcu -copy bin\Lib\GraphABCLinux.pas Release\PascalABCNETLinux\Lib\GraphABCLinux.pas -copy bin\Lib\GraphABCLinuxHelper.pas Release\PascalABCNETLinux\Lib\GraphABCLinuxHelper.pas copy bin\Lib\IniFile.pas Release\PascalABCNETLinux\Lib\IniFile.pas copy bin\Lib\IniFile.pcu Release\PascalABCNETLinux\Lib\IniFile.pcu copy bin\Lib\LightPT.pas Release\PascalABCNETLinux\Lib\LightPT.pas @@ -185,8 +197,25 @@ copy bin\Lng\Rus\Warning_ib.dat Release\PascalABCNETLinux\Lng\Rus\Warning_ib.dat copy bin\Lng\Rus\_Global Release\PascalABCNETLinux\Lng\Rus\_Global copy bin\Lng\Rus\_Global_loc Release\PascalABCNETLinux\Lng\Rus\_Global_loc +xcopy InstallerSamples\!MainFeatures\ Release\Samples\!MainFeatures\ /s /e + +xcopy InstallerSamples\!Tutorial\ Release\Samples\!Tutorial\ /s /e +xcopy InstallerSamples\!РусскиеИсполнители\ Release\Samples\!РусскиеИсполнители\ /s /e +xcopy InstallerSamples\Algorithms\ Release\Samples\Algorithms\ /s /e +xcopy InstallerSamples\Applications\ Release\Samples\Applications\ /s /e +xcopy InstallerSamples\Games\ Release\Samples\Games\ /s /e +xcopy InstallerSamples\LanguageFeatures\ Release\Samples\LanguageFeatures\ /s /e +xcopy InstallerSamples\LINQ\ Release\Samples\LINQ\ /s /e +xcopy InstallerSamples\NETLibraries\ Release\Samples\NETLibraries\ /s /e +xcopy InstallerSamples\Other\ Release\Samples\Other\ /s /e +xcopy InstallerSamples\StandardUnits\ Release\Samples\StandardUnits\ /s /e +xcopy InstallerSamples\WhatsNew\ Release\Samples\WhatsNew\ /s /e + +xcopy InstallerSamples\Graphics\GraphABC\ Release\Samples\Graphics\GraphABC\ /s /e + cd Release ..\Utils\pkzipc\pkzipc.exe -add -dir=current PascalABCNETLinux.zip PascalABCNETLinux\*.* +..\Utils\pkzipc\pkzipc.exe -add -dir=current PascalABCNETLinux.zip Samples\*.* cd .. diff --git a/bin/Lib/Drawman.pas b/bin/Lib/Drawman.pas index 8aba5acdd..1a923dccb 100644 --- a/bin/Lib/Drawman.pas +++ b/bin/Lib/Drawman.pas @@ -55,7 +55,7 @@ procedure __FinalizeModule__; implementation -uses DMTaskMaker,DMZadan,DrawmanField; +uses DMTaskMaker,DMZadan,DrawManField; procedure SetDrawmanWidth(w: integer); begin diff --git a/bin/Lib/GraphABC.pas b/bin/Lib/GraphABC.pas index 818d14a47..e2492d330 100644 --- a/bin/Lib/GraphABC.pas +++ b/bin/Lib/GraphABC.pas @@ -2051,7 +2051,8 @@ end; procedure Picture.CopyRect(dst: System.Drawing.Rectangle; bmp: Bitmap; src: System.Drawing.Rectangle); begin // Copy src portion of bmp on dst rectangle of this picture - var tempbmp := GetView(bmp, src); + //var tempbmp := GetView(bmp, src); // SSM 17/09/22 заменил это сложное - не работает под Linux + var tempbmp := bmp.Clone(src,bmp.PixelFormat); // gb.DrawImage(bmp,dst,src,GraphicsUnit.Pixel); gb.DrawImage(tempbmp, dst); tempbmp.Dispose; diff --git a/bin/Lib/LightPT.pas b/bin/Lib/LightPT.pas index fdba323ae..c75a6d169 100644 --- a/bin/Lib/LightPT.pas +++ b/bin/Lib/LightPT.pas @@ -137,6 +137,19 @@ type function Info: string; override := $'OutputCount({Count},{n})'; end; + OutputCount2Exception = class(PTException) // Ровно Count + Count: integer; // Count - сколько выведено + i: integer; // n - какой номер требуется вывести + constructor(Count, i: integer); + begin + Self.Count := Count; + Self.i := i; + TaskResult := IOError; + TaskException := Self; + end; + + function Info: string; override := $'Output2Count({Count},{i})'; + end; OutputTypeException = class(PTException) n: integer; // номер параметра ExpectedType, ActualType: string; @@ -176,8 +189,8 @@ var OutputString := new StringBuilder; OutputList := new List; InputList := new List; - InitialOutputList := new List; - InitialInputList := new List; + InitialOutputList := new List; // тут только типы и количество + InitialInputList := new List; // тут только типы и количество CheckTask: procedure(name: string); @@ -185,6 +198,8 @@ var var TaskName := ExtractFileName(System.Environment.GetCommandLineArgs[0]).Replace('.exe', ''); +// Сервисные функции + function IsPT := System.Type.GetType('PT4.PT4') <> nil; function IsRobot := System.Type.GetType('RobotField.RobotField'); @@ -197,6 +212,7 @@ function cStr := typeof(string); function cBool := typeof(boolean); function cChar := typeof(char); +/// Полный путь к папке auth-файла function FindAuthDat: string; begin var auth := 'auth.dat'; @@ -223,6 +239,8 @@ begin end; end; +// Шифрование-дешифрование + function ProcessorId: string; begin var mbs := new ManagementObjectSearcher('Select ProcessorId From Win32_processor'); @@ -357,16 +375,25 @@ begin raise new InputCount2Exception(InputList.Count, i + 1) end; +procedure CheckOutput2Count(i: integer); +begin + if OutputList.Count <= i then + raise new OutputCount2Exception(OutputList.Count, i + 1) +end; + function IsInt(i: integer) := InputList[i] is integer; - function IsRe(i: integer) := InputList[i] is real; - function IsStr(i: integer) := InputList[i] is string; - function IsBoo(i: integer) := InputList[i] is boolean; - function IsChr(i: integer) := InputList[i] is char; +function OutIsInt(i: integer) := OutputList[i] is integer; +function OutIsRe(i: integer) := OutputList[i] is real; +function OutIsStr(i: integer) := OutputList[i] is string; +function OutIsBoo(i: integer) := OutputList[i] is boolean; +function OutIsChr(i: integer) := OutputList[i] is char; + + function Int(i: integer): integer; begin CheckInput2Count(i); @@ -407,6 +434,46 @@ begin Result := char(InputList[i]); end; +function OutAsInt(i: integer): integer; +begin + CheckOutput2Count(i); + if not OutIsInt(i) then + raise new OutputTypeException(i + 1, 'integer', TypeName(OutputList[i])); + Result := integer(OutputList[i]); +end; + +function OutAsRe(i: integer): real; +begin + CheckOutput2Count(i); + if not OutIsRe(i) then + raise new OutputTypeException(i + 1, 'real', TypeName(OutputList[i])); + Result := real(OutputList[i]); +end; + +function OutAsBoo(i: integer): boolean; +begin + CheckOutput2Count(i); + if not OutIsBoo(i) then + raise new OutputTypeException(i + 1, 'boolean', TypeName(OutputList[i])); + Result := boolean(OutputList[i]); +end; + +function OutAsChr(i: integer): char; +begin + CheckOutput2Count(i); + if not OutIsChr(i) then + raise new OutputTypeException(i + 1, 'char', TypeName(OutputList[i])); + Result := char(OutputList[i]); +end; + +function OutAsStr(i: integer): string; +begin + CheckOutput2Count(i); + if not OutIsStr(i) then + raise new OutputTypeException(i + 1, 'string', TypeName(OutputList[i])); + Result := string(OutputList[i]); +end; + function Int: integer; begin Result := Int(Cur); @@ -445,6 +512,55 @@ function IntArr(n: integer): array of integer := (1..n).Select(x -> Int).ToArray function ReArr(n: integer): array of real := (1..n).Select(x -> Re).ToArray; +// функции, возвращающие входные и выходные списки, а также их срезы, приведенные к нужному типу + +function InputListAsIntegers: array of integer := InputList.Select((x,i) -> Int(i)).ToArray; +function InputListAsReals: array of real := InputList.Select((x,i) -> Re(i)).ToArray; +function InputListAsBooleans: array of boolean := InputList.Select((x,i) -> Boo(i)).ToArray; +function InputListAsChars: array of char := InputList.Select((x,i) -> Chr(i)).ToArray; +function InputListAsStrings: array of string := InputList.Select((x,i) -> Str(i)).ToArray; + +function OutputListAsIntegers: array of integer := OutputList.Select((x,i) -> OutAsInt(i)).ToArray; +function OutputListAsReals: array of real := OutputList.Select((x,i) -> OutAsRe(i)).ToArray; +function OutputListAsBooleans: array of boolean := OutputList.Select((x,i) -> OutAsBoo(i)).ToArray; +function OutputListAsChars: array of char := OutputList.Select((x,i) -> OutAsChr(i)).ToArray; +function OutputListAsStrings: array of string := OutputList.Select((x,i) -> OutAsStr(i)).ToArray; + +function InputListSliceAsIntegers(a,b: integer): array of integer := (a..b).Select(i->Int(i)).ToArray; +function InputListSliceAsReals(a,b: integer): array of real := (a..b).Select(i->Re(i)).ToArray; +function InputListSliceAsBooleans(a,b: integer): array of boolean := (a..b).Select(i->Boo(i)).ToArray; +function InputListSliceAsChars(a,b: integer): array of char := (a..b).Select(i->Chr(i)).ToArray; +function InputListSliceAsStrings(a,b: integer): array of string := (a..b).Select(i->Str(i)).ToArray; + +function OutputListSliceAsIntegers(a,b: integer): array of integer := (a..b).Select(i->OutAsInt(i)).ToArray; +function OutputListSliceAsReals(a,b: integer): array of real := (a..b).Select(i->OutAsRe(i)).ToArray; +function OutputListSliceAsBooleans(a,b: integer): array of boolean := (a..b).Select(i->OutAsBoo(i)).ToArray; +function OutputListSliceAsChars(a,b: integer): array of char := (a..b).Select(i->OutAsChr(i)).ToArray; +function OutputListSliceAsStrings(a,b: integer): array of string := (a..b).Select(i->OutAsStr(i)).ToArray; + +function ConvertOne(ob: Object): Object; +begin + Result := ob; + if ob is string then + begin + var s := string(ob); + var ival: integer; + var rval: real; + if s.TryToInteger(ival) then + Result := ival + else if s.TryToReal(rval) then + Result := rval + end +end; + +procedure ConvertStringsToNumbersInOutputList; +begin + for var i:=0 to OutputList.Count - 1 do + OutputList[i] := ConvertOne(OutputList[i]); +end; + +// -------------- Переопределенные функции с заполнением ввода и вывода + function Random(a, b: integer): integer; begin Result := PABCSystem.Random(a, b); @@ -532,6 +648,9 @@ begin InputList.Add(Result[i]); end; +/// Возвращает массив размера n, заполненный случайными целыми значениями +function ArrRandomInteger(n: integer): array of integer := ArrRandomInteger(n,0,100); + /// Возвращает массив размера n, заполненный случайными вещественными значениями function ArrRandomReal(n: integer; a: real; b: real): array of real; begin @@ -541,6 +660,114 @@ begin InputList.Add(Result[i]); end; +/// Возвращает массив размера n, заполненный случайными вещественными значениями +function ArrRandomReal(n: integer): array of real := ArrRandomReal(n,0,10); + +/// Возвращает массив из count элементов, заполненных значениями gen(i) +function ArrGen(count: integer; gen: integer->T): array of T; +begin + Result := PABCSystem.ArrGen(count,gen); + if IsPT then exit; + for var i:=0 to Result.Length-1 do + InputList.Add(Result[i]); +end; + +/// Возвращает массив из count элементов, заполненных значениями gen(i), начиная с i=from +function ArrGen(count: integer; gen: integer->T; from: integer): array of T; +begin + Result := PABCSystem.ArrGen(count,gen,from); + if IsPT then exit; + for var i:=0 to Result.Length-1 do + InputList.Add(Result[i]); +end; + +/// Возвращает массив из count элементов, начинающихся с first, с функцией next перехода от предыдущего к следующему +function ArrGen(count: integer; first: T; next: T->T): array of T; +begin + Result := PABCSystem.ArrGen(count,first,next); + if IsPT then exit; + for var i:=0 to Result.Length-1 do + InputList.Add(Result[i]); +end; + +/// Возвращает массив из count элементов, начинающихся с first и second, с функцией next перехода от двух предыдущих к следующему +function ArrGen(count: integer; first, second: T; next: (T,T) ->T): array of T; +begin + Result := PABCSystem.ArrGen(count,first,second,next); + if IsPT then exit; + for var i:=0 to Result.Length-1 do + InputList.Add(Result[i]); +end; + +/// Возвращает массив из n целых, введенных с клавиатуры +function ReadArrInteger(n: integer): array of integer; +begin + Result := PABCSystem.ReadArrInteger(n); + if IsPT then exit; + for var i:=0 to Result.Length-1 do + InputList.Add(Result[i]); +end; + +/// Возвращает массив из n вещественных, введенных с клавиатуры +function ReadArrReal(n: integer): array of real; +begin + Result := PABCSystem.ReadArrReal(n); + if IsPT then exit; + for var i:=0 to Result.Length-1 do + InputList.Add(Result[i]); +end; + +/// Возвращает массив из n строк, введенных с клавиатуры +function ReadArrString(n: integer): array of string; +begin + Result := PABCSystem.ReadArrString(n); + if IsPT then exit; + for var i:=0 to Result.Length-1 do + InputList.Add(Result[i]); +end; + +/// Возвращает матрицу m на n целых, введенных с клавиатуры +function ReadMatrInteger(m, n: integer): array [,] of integer; +begin + Result := PABCSystem.ReadMatrInteger(m,n); + if IsPT then exit; + foreach var x in Result.ElementsByRow do + InputList.Add(x); +end; + +/// Возвращает матрицу m на n вещественных, введенных с клавиатуры +function ReadMatrReal(m, n: integer): array [,] of real; +begin + Result := PABCSystem.ReadMatrReal(m,n); + if IsPT then exit; + foreach var x in Result.ElementsByRow do + InputList.Add(x); +end; + +/// Возвращает двумерный массив размера m x n, заполненный случайными целыми значениями +function MatrRandomInteger(m: integer; n: integer; a: integer; b: integer): array [,] of integer; +begin + Result := PABCSystem.MatrRandomInteger(m,n,a,b); + if IsPT then exit; + foreach var x in Result.ElementsByRow do + InputList.Add(x); +end; + +/// Возвращает двумерный массив размера m x n, заполненный случайными целыми значениями +function MatrRandomInteger(m: integer; n: integer): array [,] of integer := MatrRandomInteger(m,n,0,100); + +/// Возвращает двумерный массив размера m x n, заполненный случайными вещественными значениями +function MatrRandomReal(m: integer := 5; n: integer := 5; a: real := 0; b: real := 10): array [,] of real; +begin + +end; + +/// Возвращает двумерный массив размера m x n, заполненный элементами gen(i,j) +function MatrGen(m, n: integer; gen: (integer,integer)->T): array [,] of T; +begin + +end; + function ReadString: string; begin Result := PABCSystem.ReadString; @@ -622,7 +849,7 @@ type procedure write(obj: object); override; begin inherited write(obj); - OutputString += obj.ToString; + OutputString += _ObjectToString(obj); OutputList += obj; DoNewLineBeforeMessage := True; end; @@ -744,6 +971,8 @@ type DoNewLineBeforeMessage := True; end; end; + +// конец переопределенных функций с заполнением ввода-вывода function ToObjArray(a: array of integer) := a.Select(x -> object(x)).ToArray; @@ -766,29 +995,61 @@ begin raise new OutputCountException(OutputList.Count, a.Length); end; -procedure CheckOutput(params a: array of object); +procedure CheckOutput(params arr: array of object); begin if (TaskResult = InitialTask) or (TaskResult = BadInitialTask) then exit; - var mn := Min(a.Length, OutputList.Count); + var mn := Min(arr.Length, OutputList.Count); TaskResult := Solved; // Несоответствие типов for var i := 0 to mn - 1 do begin - if (a[i].GetType.Name = 'RuntimeType') and (a[i] <> OutputList[i].GetType) then - raise new OutputTypeException(i + 1, TypeToTypeName(a[i] as System.Type), TypeName(OutputList[i])) - else if (a[i].GetType.Name <> 'RuntimeType') and (a[i].GetType <> OutputList[i].GetType) then - raise new OutputTypeException(i + 1, TypeName(a[i]), TypeName(OutputList[i])); + if (arr[i].GetType.Name = 'RuntimeType') and (arr[i] <> OutputList[i].GetType) then + raise new OutputTypeException(i + 1, TypeToTypeName(arr[i] as System.Type), TypeName(OutputList[i])) + else if (arr[i].GetType.Name <> 'RuntimeType') and (arr[i].GetType <> OutputList[i].GetType) then + raise new OutputTypeException(i + 1, TypeName(arr[i]), TypeName(OutputList[i])); end; // Несоответствие количества выводимых параметров - if a.Length <> OutputList.Count then - raise new OutputCountException(OutputList.Count, a.Length); + if arr.Length <> OutputList.Count then + raise new OutputCountException(OutputList.Count, arr.Length); // Несоответствие значений for var i := 0 to mn - 1 do - if (a[i].GetType.Name <> 'RuntimeType') and not CompareValues(a[i], OutputList[i]) then + if (arr[i].GetType.Name <> 'RuntimeType') and not CompareValues(arr[i], OutputList[i]) then + begin + TaskResult := BadSolution; // Если типы разные, то IOErrorSolution + exit; + end; +end; + +procedure CheckOutputAfterInitial(params arr: array of object); // проверить только то, что после исходного вывода +begin + if (TaskResult = InitialTask) or (TaskResult = BadInitialTask) then + exit; + + // Здесь всегда OutputList.Count > InitialOutputList.Count + // Если arr.Length > OutputList.Count - InitialOutputList.Count, то мы не вывели часть данных + // Если arr.Length < OutputList.Count - InitialOutputList.Count, то мы вывели больше чем надо + + if arr.Length <> OutputList.Count - InitialOutputList.Count then + raise new OutputCountException(OutputList.Count, InitialOutputList.Count + arr.Length); + + TaskResult := Solved; + // Несоответствие типов + var a := OutputList.Count - arr.Length; + for var i := a to OutputList.Count - 1 do + begin + if (arr[i-a].GetType.Name = 'RuntimeType') and (arr[i-a] <> OutputList[i].GetType) then + raise new OutputTypeException(i + 1, TypeToTypeName(arr[i-a] as System.Type), TypeName(OutputList[i])) + else if (arr[i-a].GetType.Name <> 'RuntimeType') and (arr[i-a].GetType <> OutputList[i].GetType) then + raise new OutputTypeException(i + 1, TypeName(arr[i-a]), TypeName(OutputList[i])); + end; + + // Несоответствие значений + for var i := a to OutputList.Count - 1 do + if (arr[i-a].GetType.Name <> 'RuntimeType') and not CompareValues(arr[i-a], OutputList[i]) then begin TaskResult := BadSolution; // Если типы разные, то IOErrorSolution exit; @@ -820,6 +1081,15 @@ procedure CheckOutputSeq(a: sequence of object) := CheckOutput(a.ToArray); procedure CheckOutputSeq(a: ObjectList) := CheckOutput(a.lst.ToArray); +procedure CheckOutputAfterInitialSeq(seq: sequence of integer) := CheckOutputAfterInitial(ToObjArray(seq.ToArray)); +procedure CheckOutputAfterInitialSeq(seq: sequence of real) := CheckOutputAfterInitial(ToObjArray(seq.ToArray)); +procedure CheckOutputAfterInitialSeq(seq: sequence of string) := CheckOutputAfterInitial(ToObjArray(seq.ToArray)); +procedure CheckOutputAfterInitialSeq(seq: sequence of boolean) := CheckOutputAfterInitial(ToObjArray(seq.ToArray)); +procedure CheckOutputAfterInitialSeq(seq: sequence of char) := CheckOutputAfterInitial(ToObjArray(seq.ToArray)); +procedure CheckOutputAfterInitialSeq(seq: sequence of object) := CheckOutputAfterInitial(seq.ToArray); +procedure CheckOutputAfterInitialSeq(seq: ObjectList) := CheckOutputAfterInitial(seq.lst.ToArray); + + procedure ClearOutputListFromSpaces; begin OutputList := OutputList.Where(s -> (not (s is string)) or ((s as string) <> ' ')).ToList; @@ -1131,6 +1401,12 @@ begin ColoredMessage($'Требуется вывести {NValues(e.n)}', MsgColorGray) else ColoredMessage($'Выведено {NValues(e.Count)}, а требуется вывести {e.n}', MsgColorOrange); end; + on e: OutputCount2Exception do + begin + if e.Count = 0 then + ColoredMessage($'Требуется вывести по крайней мере {NValues(e.i)}', MsgColorGray) + else ColoredMessage($'Выведено {NValues(e.Count)}, а требуется вывести по крайней мере {e.i}', MsgColorOrange); + end; on e: InputTypeException do begin //Writeln(#10+$'Неверно указан тип при вводе исходных данных'); diff --git a/bin/Lib/PABCSystem.pas b/bin/Lib/PABCSystem.pas index 824ea19b6..2b305d171 100644 --- a/bin/Lib/PABCSystem.pas +++ b/bin/Lib/PABCSystem.pas @@ -2310,9 +2310,13 @@ function Arr(a: CharRange): array of char; /// Возвращает массив размера n, заполненный случайными целыми значениями function ArrRandom(n: integer := 10; a: integer := 0; b: integer := 100): array of integer; /// Возвращает массив размера n, заполненный случайными целыми значениями -function ArrRandomInteger(n: integer := 10; a: integer := 0; b: integer := 100): array of integer; +function ArrRandomInteger(n: integer; a: integer; b: integer): array of integer; +/// Возвращает массив размера n, заполненный случайными целыми значениями +function ArrRandomInteger(n: integer := 10): array of integer; /// Возвращает массив размера n, заполненный случайными вещественными значениями -function ArrRandomReal(n: integer := 10; a: real := 0; b: real := 10): array of real; +function ArrRandomReal(n: integer; a: real; b: real): array of real; +/// Возвращает массив размера n, заполненный случайными вещественными значениями +function ArrRandomReal(n: integer := 10): array of real; /// Возвращает массив из count элементов, заполненных значениями gen(i) function ArrGen(count: integer; gen: integer->T): array of T; /// Возвращает массив из count элементов, заполненных значениями gen(i), начиная с i=from @@ -2381,22 +2385,22 @@ function MatrByCol(a: sequence of sequence of T): array [,] of T; /// Генерирует двумерный массив по столбцам из последовательности function MatrByCol(m,n: integer; a: sequence of T): array [,] of T; +/// Возвращает матрицу m на n целых, введенных с клавиатуры +function ReadMatrInteger(m, n: integer): array [,] of integer; +/// Возвращает матрицу m на n вещественных, введенных с клавиатуры +function ReadMatrReal(m, n: integer): array [,] of real; /// Возвращает двумерный массив размера m x n, заполненный случайными целыми значениями function MatrRandom(m: integer := 5; n: integer := 5; a: integer := 0; b: integer := 100): array [,] of integer; /// Возвращает двумерный массив размера m x n, заполненный случайными целыми значениями function MatrRandomInteger(m: integer := 5; n: integer := 5; a: integer := 0; b: integer := 100): array [,] of integer; /// Возвращает двумерный массив размера m x n, заполненный случайными вещественными значениями function MatrRandomReal(m: integer := 5; n: integer := 5; a: real := 0; b: real := 10): array [,] of real; -/// Возвращает двумерный массив размера m x n, заполненный элементами x -function MatrFill(m, n: integer; x: T): array [,] of T; /// Возвращает двумерный массив размера m x n, заполненный элементами gen(i,j) function MatrGen(m, n: integer; gen: (integer,integer)->T): array [,] of T; +/// Возвращает двумерный массив размера m x n, заполненный элементами x +function MatrFill(m, n: integer; x: T): array [,] of T; /// Транспонирует двумерный массив function Transpose(a: array [,] of T): array [,] of T; -/// Возвращает матрицу m на n целых, введенных с клавиатуры -function ReadMatrInteger(m, n: integer): array [,] of integer; -/// Возвращает матрицу m на n вещественных, введенных с клавиатуры -function ReadMatrReal(m, n: integer): array [,] of real; // ----------------------------------------------------- //>> Подпрограммы для создания кортежей # Subroutines for tuple generation @@ -4782,6 +4786,8 @@ begin Result := ArrRandom(n, a, b); end; +function ArrRandomInteger(n: integer) := ArrRandomInteger(n,0,100); + function ArrRandomReal(n: integer; a: real; b: real): array of real; begin Result := new real[n]; @@ -4789,6 +4795,8 @@ begin Result[i] := Random() * (b - a) + a; end; +function ArrRandomReal(n: integer) := ArrRandomReal(n,0,10); + function SeqRandom(n: integer; a: integer; b: integer): sequence of integer; begin loop n do @@ -12145,12 +12153,29 @@ begin end; end; -/// Возвращает n-тую декартову степень множества элементов, заданного массивом +/// Возвращает n-тую декартову степень множества элементов, заданного последовательностью function Cartesian(Self: sequence of T; n: integer): sequence of array of T; extensionmethod; begin Result := Self.ToArray.Cartesian(n); end; +/// Возвращает все перестановки букв в строке в виде последовательности строк +function Permutations(Self: string): sequence of string; extensionmethod +:= Self.ToCharArray.Permutations.Select(p -> new string(p)); + +/// Возвращает все частичные перестановки букв строки по m символов в виде последовательности строк +function Permutations(Self: string; m: integer): sequence of string; extensionmethod +:= Self.ToCharArray.Permutations(m).Select(p -> new string(p)); + +/// Возвращает n-тую декартову степень множества символов, заданного строкой +function Cartesian(Self: string; n: integer): sequence of string; extensionmethod +:= Self.ToCharArray.Cartesian(n).Select(p -> new string(p)); + +/// Возвращает все сочетания по m элементов +function Combinations(Self: string; m: integer): sequence of string; extensionmethod +:= Self.ToCharArray.Combinations(m).Select(p -> new string(p)); + + // Внутренние функции для одномерных массивов ///-- diff --git a/bin/Lib/School.pas b/bin/Lib/School.pas index ad6d8b2fa..b85f24066 100644 --- a/bin/Lib/School.pas +++ b/bin/Lib/School.pas @@ -964,22 +964,6 @@ end; procedure SwapSubstr(var Self: string; ss1, ss2: string); extensionmethod := SwapSubstr(Self, ss1, ss2); -/// Возвращает все перестановки букв в строке в виде последовательности строк -function Permutations(Self: string): sequence of string; extensionmethod -:= Self.ToCharArray.Permutations.Select(p -> new string(p)); - -/// Возвращает все частичные перестановки букв строки по m символов в виде последовательности строк -function Permutations(Self: string; m: integer): sequence of string; extensionmethod -:= Self.ToCharArray.Permutations(m).Select(p -> new string(p)); - -/// Возвращает n-тую декартову степень множества символов, заданного строкой -function Cartesian(Self: string; n: integer): sequence of string; extensionmethod -:= Self.ToCharArray.Cartesian(n).Select(p -> new string(p)); - -/// Возвращает все сочетания по m элементов -function Combinations(Self: string; m: integer): sequence of string; extensionmethod -:= Self.ToCharArray.Combinations(m).Select(p -> new string(p)); - {$endregion} begin