public class MyComparer : System.Collections.IComparer { public MyComparer() {
}
#region IComparer メンバ
public int Compare(object x, object y) { string a = (string)x; string b = (string)y;
//正規表現で末尾の数字を取得 System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("(?<num>\\d*)$"); int numA = int.Parse(regex.Match(a).Groups["num"].Value); int numB = int.Parse(regex.Match(b).Groups["num"].Value);
return numA - numB; }
#endregion }
という風にIComparerの実装を作っておいて
string[] ary = new string[] { "ABC012", "ZZ101", "Z99", "A23", "B11" }; Array.Sort(ary, new MyComparer());
with Ada.Numerics.Discrete_Random,Ada.Text_Io,Ada.Integer_Text_Io,Ada.Calendar; use Ada.Text_Io,Ada.Integer_Text_Io,Ada.Calendar; procedure game Is package R Is New Ada.Numerics.Discrete_Random(natural); use R; type Four_Array is array(1..4)of Integer; function Generate Return Integer is seed:Generator; begin Reset(seed,Integer(Seconds(Clock)*100)); return Random(Seed) mod 10; end Generate; function Search(Target:Four_array;Seed:In Integer) Return integer Is begin for I in 1..4 loop if Target(I) = Seed then return i; end if; end loop; return 0; end Search; procedure Initialize(computer:In out Four_array) is begin for I in 1..4 loop computer(I):=-1; end loop; end initialize;
procedure Decide(computer:in out Four_array) Is int:Integer; begin Initialize(Computer); for I in 1..4 Loop loop Int:=Generate;exit when Search(computer,Int) = 0; end loop; Computer(I):=Int;delay 0.01; end loop; end Decide; procedure Read(Player:in out Four_array) is int,Index:Integer:=1;Char:character; begin while Index <= 4 Loop Get_Immediate(char); case Char is when '0'..'9' => Int:=Character'Pos(char)-16#30#; if Search(Player,int) /= 0 then New_Line;Put_Line("その値はもう使えません"); for I in 1..Index-1 loop Put(Character'Val(Player(i)+16#30#)); end loop; else Put(char);Player(index):=int;Index:=Index+1; end if; when others => New_Line;Put_Line("0から9までの数値を入れてください"); for I in 1..Index-1 Loop Put(Character'Val(Player(I)+16#30#)); end loop; end case; end loop; end Read;
function Compare(computer,Player:in Four_array) return Boolean is Hit_Count:Integer:=0; Blow_Count:Integer:=0; Search_Result:integer; begin for I In 1..4 Loop Search_Result:=Search(Computer,Player(i)); if Search_Result = I Then Hit_Count:=Hit_Count+1; elsif Search_result /= 0 then Blow_Count:=Blow_Count+1; end if; end loop; New_Line; Put_Line("Hit : "&Integer'Image(Hit_count)); Put_Line("Blow : "&Integer'Image(Blow_count)); if Hit_Count = 4 then return True; end if; return False; end Compare; computer,player:Four_Array; begin Decide(computer); loop Initialize(player); Read(Player); exit when Compare(computer,Player); end loop; end game;
Atlas V: http://www.ddci.com/programs_atlasv.shtml Lockheed Martin Space Systems depends on TADS to develop modern, object-oriented real-time flight control software for the new Atlas V launch vehicle.
The maiden voyage of Lockheed Martin’s first Atlas V rocket lifted off from Space Launch Complex 41 at Cape Canaveral on August 12, 2002, freed from its earthly bonds by flight control software created with DDC-I’s Tartan Ada Development System (TADS).
The effect of translating and executing such a program unit.
The manner in which program units may be combined to form Ada programs.
The predefined program units that a conforming implementation must supply.
The permissible variations within the standard, and the manner in which they must be specified.
Those violations of the standard that a conforming implementation is required to detect, and the effect of attempting to translate or execute a program unit containing such violations.
Those violations of the standard that a conforming implementation is not required to detect.
This standard does not specify:
The means whereby a program unit written in Ada is transformed into object code executable by a processor.
The means whereby translation or execution of program units is invoked and the executing units are controlled.
The size or speed of the object code, or the relative execution speed of different language constructs.
The form or contents of any listings produced by implementations; in particular, the form or contents of error or warning messages.
The effect of executing a program unit that contains any violation that a conforming implementation is not required to detect.
The size of a program or program unit that will exceed the capacity of a particular conforming implementation.