static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); NameComparator nameComparator = new NameComparator(); AgeComparator ageComparator = new AgeComparator(); SortedSet <Person> peopleOrderedByName = new SortedSet <Person>(nameComparator); SortedSet <Person> peopleOrderedByAge = new SortedSet <Person>(ageComparator); for (int i = 0; i < n; i++) { var tokens = Console.ReadLine().Split().ToList(); string name = tokens[0]; int age = int.Parse(tokens[1]); Person person = new Person(name, age); peopleOrderedByName.Add(person); peopleOrderedByAge.Add(person); } foreach (var item in peopleOrderedByName) { Console.WriteLine(item.name + ' ' + item.age); } foreach (var item in peopleOrderedByAge) { Console.WriteLine(item.name + ' ' + item.age); } }
static void Main(string[] args) { var nameComparator = new NameComparator(); var ageComparator = new AgeComparator(); var personSet1 = new SortedSet <Person>(nameComparator); var personSet2 = new SortedSet <Person>(ageComparator); int numberOfPersons = int.Parse(Console.ReadLine()); for (int i = 0; i < numberOfPersons; i++) { var personInput = Console.ReadLine().Split(); var name = personInput[0]; var age = int.Parse(personInput[1]); var person = new Person(name, age); personSet1.Add(person); personSet2.Add(person); } PrintPersonSet(personSet1); PrintPersonSet(personSet2); }
public static void Main() { NameComparator nameComparator = new NameComparator(); AgeComparator ageComparator = new AgeComparator(); SortedSet <Person> personsByName = new SortedSet <Person>(nameComparator); SortedSet <Person> personsByAge = new SortedSet <Person>(ageComparator); int n = int.Parse(Console.ReadLine()); for (int counter = 0; counter < n; counter++) { List <string> args = Console.ReadLine() .Split(' ', StringSplitOptions.RemoveEmptyEntries) .ToList(); string name = args[0]; int age = int.Parse(args[1]); Person person = new Person(name, age); personsByName.Add(person); personsByAge.Add(person); } Console.WriteLine(string.Join(Environment.NewLine, personsByName)); Console.WriteLine(string.Join(Environment.NewLine, personsByAge)); }
static void Main(string[] args) { AgeComparator ageComparator = new AgeComparator(); NameComparator nameComparator = new NameComparator(); SortedSet <Person> ageComparedPeople = new SortedSet <Person>(ageComparator); SortedSet <Person> nameComparedPeople = new SortedSet <Person>(nameComparator); int peopleCount = int.Parse(Console.ReadLine()); for (int index = 0; index < peopleCount; index++) { string[] person = Console.ReadLine() .Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries) .ToArray(); string name = person[0]; int age = int.Parse(person[1]); ageComparedPeople.Add(new Person(name, age)); nameComparedPeople.Add(new Person(name, age)); } foreach (var person in nameComparedPeople) { Console.WriteLine(person.Name + " " + person.Age); } foreach (var person in ageComparedPeople) { Console.WriteLine(person.Name + " " + person.Age); } }
static void Main(string[] args) { NameComparator nameComparator = new NameComparator(); SortedSet <Person> peopleByName = new SortedSet <Person>(nameComparator); AgeComparator ageComparator = new AgeComparator(); SortedSet <Person> peopleByAge = new SortedSet <Person>(ageComparator); var n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { var person = Console.ReadLine() .Split(' ') .ToList(); peopleByName.Add(new Person(person[0], int.Parse(person[1]))); peopleByAge.Add(new Person(person[0], int.Parse(person[1]))); } Console.WriteLine(string.Join(Environment.NewLine, peopleByName)); Console.WriteLine(string.Join(Environment.NewLine, peopleByAge)); }
static ProcessEnvironment() { NameComparator = new NameComparator(); EntryComparator = new EntryComparator(); TheEnvironment = new ProcessEnvironment(); TheUnmodifiableEnvironment = Collections.UnmodifiableMap(TheEnvironment); String envblock = environmentBlock(); int beg, end, eql; for (beg = 0; ((end = envblock.IndexOf('\u0000', beg)) != -1 && (eql = envblock.IndexOf('=', beg + 1)) != -1); beg = end + 1) { // An initial `=' indicates a magic Windows variable name -- OK // Ignore corrupted environment strings. if (eql < end) { TheEnvironment.Put(envblock.Substring(beg, eql - beg), StringHelperClass.SubstringSpecial(envblock, eql + 1, end)); } } TheCaseInsensitiveEnvironment = new TreeMap <>(NameComparator); TheCaseInsensitiveEnvironment.PutAll(TheEnvironment); }
public int Compare(Map_Entry <String, String> e1, Map_Entry <String, String> e2) { return(NameComparator.Compare(e1.Key, e2.Key)); }