Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp1
- {
- internal class Program
- {
- private static Random random = new Random();
- static void Main(string[] args)
- {
- List<Person> people = new List<Person>();
- for (int i = 0; i < 10; ++i)
- {
- people.Add(new Person($"Person{i}", (i + 1) * 10, random.Next(200, 1501)));
- }
- //people[4] = people[0];
- bool azE = HalmazE(people);
- Console.WriteLine(azE);
- bool tartE = TartalmazE(people, people[0]);
- Console.WriteLine(tartE);
- bool tartENemxD = TartalmazE(people, new Person("xy", 1, 1));
- Console.WriteLine(tartENemxD);
- bool reszE = ReszhalmazE(people, new List<Person>() { people[0], people[1], people[2] });
- Console.WriteLine(reszE);
- Console.Read();
- }
- private static bool HalmazE(List<Person> people)
- {
- int i = 1;
- while (i < people.Count && people[i] != people[i-1])
- {
- ++i;
- }
- return i == people.Count;
- }
- private static bool TartalmazE(List<Person> people, Person person)
- {
- int bal = 0;
- int jobb = people.Count-1;
- int center = (bal+jobb) / 2;
- while (bal <= jobb && people[center].CompareTo(person) != 0)
- {
- if (people[center].CompareTo(person) == -1)
- {
- jobb = center - 1;
- }
- else
- {
- bal = center + 1;
- }
- center = (bal+jobb) / 2;
- }
- return bal <= jobb;
- }
- private static bool ReszhalmazE(List<Person> people, List<Person> people2)
- {
- int j = 0;
- int i = 0;
- while (i < people.Count && j < people2.Count && people[i].Age >= people2[i].Age)
- {
- if (people[i] == people2[i])
- {
- ++i;
- }
- ++j;
- }
- return i >= j;
- }
- }
- }
- ---------------------------------------------------------------------------------------------------
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp1
- {
- internal class Person : IComparable
- {
- private int age;
- private int salary;
- private string name;
- public Person(string name, int age, int salary)
- {
- this.name = name;
- this.age = age;
- this.salary = salary;
- }
- public string Name { get => this.name; set => this.name = value; }
- public int Age { get => this.age; set => this.age = value; }
- public int Salary { get => this.salary; set => this.salary = value; }
- public int CompareTo(object obj)
- {
- if (obj == null)
- {
- Person p = obj as Person;
- if (p.age > this.age) return 1;
- if (p.age < this.age) return -1;
- }
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement