Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// III.4
- class Program
- {
- struct Skiers
- {
- public string name;
- public double res;
- public Skiers(string name0, double res0)
- {
- name = name0;
- res = res0;
- }
- }
- static void Sort(Skiers[] gr)
- {
- double min;
- int imin;
- for (int i = 0; i < gr.Length - 1; i++)
- {
- min = gr[i].res;
- imin = i;
- for (int k = i + 1; k < gr.Length; k++)
- {
- if (gr[k].res < min)
- {
- min = gr[k].res;
- imin = k;
- }
- }
- Skiers temp;
- temp = gr[i];
- gr[i] = gr[imin];
- gr[imin] = temp;
- }
- }
- static void Merge(Skiers[] gr1, Skiers[] gr2, Skiers[] gr)
- {
- int i = 0, j = 0, k = 0;
- while ((i < gr1.Length) && (j < gr2.Length))
- {
- if (gr1[i].res <= gr2[j].res)
- {
- gr[k] = gr1[i];
- i++;
- k++;
- }
- else
- {
- gr[k] = gr2[j];
- j++;
- k++;
- }
- }
- while (i < gr1.Length)
- {
- gr[k] = gr1[i];
- i++;
- k++;
- }
- while (j < gr2.Length)
- {
- gr[k] = gr2[j];
- j++;
- k++;
- }
- }
- static void Main(string[] args)
- {
- Skiers[] gr1 = new Skiers[5];
- gr1[0] = new Skiers("Иванов", 8.54);
- gr1[1] = new Skiers("Петров", 9.03);
- gr1[2] = new Skiers("Сидоров", 9.11);
- gr1[3] = new Skiers("Попов", 8.53);
- gr1[4] = new Skiers("Крылов", 8.48);
- Skiers[] gr2 = new Skiers[7];
- gr2[0] = new Skiers("Титов", 8.51);
- gr2[1] = new Skiers("Козлов", 8.59);
- gr2[2] = new Skiers("Матросов", 8.59);
- gr2[3] = new Skiers("Терешков", 8.47);
- gr2[4] = new Skiers("Краснов", 8.50);
- gr2[5] = new Skiers("Коваленко", 9.01);
- gr2[6] = new Skiers("Тарасов", 8.56);
- Sort(gr1);
- Console.WriteLine("Таблица результатов 1 группы:");
- for (int i = 0; i < gr1.Length; i++)
- Console.WriteLine(
- "{0}. {1}\t Результат {2,4:f2}",
- i + 1, gr1[i].name, gr1[i].res);
- Console.WriteLine();
- Sort(gr2);
- Console.WriteLine("Таблица результатов 2 группы:");
- for (int i = 0; i < gr2.Length; i++)
- Console.WriteLine(
- "{0}. {1}\t Результат {2,4:f2}",
- i + 1, gr2[i].name, gr2[i].res);
- Console.WriteLine();
- Skiers[] gr = new Skiers[12];
- Merge(gr1, gr2, gr);
- Console.WriteLine("Общая таблица результатов:");
- for (int i = 0; i < gr.Length; i++)
- Console.WriteLine(
- "{0}. {1}\t Результат {2,4:f2}",
- i + 1, gr[i].name, gr[i].res);
- Console.ReadKey();
- }
- }
- /// III.1
- struct Student
- {
- public string name;
- public double[] x;
- public Student(string name0, double[] x0)
- {
- name = name0;
- x = x0;
- }
- }
- struct Group
- {
- public int num;
- public double avrg;
- public Group (Student[] gr, int num0)
- {
- num = num0;
- avrg = 0;
- for (int i = 0; i < gr.Length; i++)
- for (int j = 0; j < 5; j++)
- {
- avrg += gr[i].x[j];
- }
- avrg /= 5 * gr.Length;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Student[] st1 = new Student[5];
- st1[0] = new Student("Иванов", new double[] { 5.0, 4.0, 5.0, 5.0, 4.0 });
- st1[1] = new Student("Петрова", new double[] { 3.0, 2.0, 4.0, 2.0, 2.0 });
- st1[2] = new Student("Сидоров", new double[] { 5.0, 4.0, 4.0, 4.0, 5.0 });
- st1[3] = new Student("Смирнова", new double[] { 3.0, 4.0, 3.0, 3.0, 4.0 });
- st1[4] = new Student("Кузнецов", new double[] { 2.0, 4.0, 5.0, 3.0, 4.0 });
- Student[] st2 = new Student[5];
- st2[0] = new Student("Соколова", new double[] { 3.0, 2.0, 4.0, 5.0, 4.0 });
- st2[1] = new Student("Попов", new double[] { 4.0, 2.0, 2.0, 5.0, 2.0 });
- st2[2] = new Student("Лебедев", new double[] { 5.0, 2.0, 5.0, 5.0, 5.0 });
- st2[3] = new Student("Иванова", new double[] { 3.0, 2.0, 3.0, 3.0, 4.0 });
- st2[4] = new Student("Новиков", new double[] { 5.0, 2.0, 5.0, 4.0, 4.0 });
- Student[] st3 = new Student[5];
- st3[0] = new Student("Лазарева", new double[] { 3.0, 4.0, 5.0, 5.0, 2.0 });
- st3[1] = new Student("Медведева", new double[] { 4.0, 2.0, 5.0, 4.0, 3.0 });
- st3[2] = new Student("Ершов", new double[] { 5.0, 3.0, 4.0, 4.0, 5.0 });
- st3[3] = new Student("Смирнов", new double[] { 3.0, 5.0, 3.0, 5.0, 4.0 });
- st3[4] = new Student("Орехова", new double[] { 2.0, 5.0, 4.0, 3.0, 4.0 });
- Group[] gr = new Group[3] {
- new Group(st1, 1), new Group(st2, 2), new Group(st3, 3) };
- double max = 0, p = 0;
- int imax = 0;
- for (int i = 0; i < gr.Length - 1; i++)
- {
- max = gr[i].avrg;
- imax = i;
- for (int j = i + 1; j < gr.Length; j++)
- {
- if (gr[j].avrg > max)
- {
- max = gr[j].avrg;
- imax = j;
- }
- }
- Group temp;
- temp = gr[i];
- gr[i] = gr[imax];
- gr[imax] = temp;
- }
- for (int i = 0; i < gr.Length; i++)
- {
- Console.WriteLine("{0}. Группа {1}\t Средний балл {2}", i + 1, gr[i].num, gr[i].avrg);
- }
- Console.ReadKey();
- }
- }
- /// III.1
- /// с классами
- class Student
- {
- public string name;
- public double[] x;
- public double avrg;
- public Student(string name0, double[] x0)
- {
- avrg = 0;
- name = name0;
- x = x0;
- for (int i = 0; i < x.Length; i++)
- {
- avrg += x[i];
- }
- avrg /= 5;
- }
- }
- class Stipend : Student
- {
- public string yn;
- public Stipend(string name0, double[] x0)
- : base(name0, x0)
- {
- if (base.avrg > 4)
- yn = "да";
- else
- yn = "нет";
- }
- }
- class Program
- {
- static void Sort(Stipend[] gr)
- {
- for (int i = 0; i < gr.Length - 1; i++)
- {
- double amax = gr[i].avrg;
- int imax = i;
- for (int j = i + 1; j < gr.Length; j++)
- {
- if (gr[j].avrg > amax)
- {
- amax = gr[j].avrg;
- imax = j;
- }
- }
- Stipend temp;
- temp = gr[imax];
- gr[imax] = gr[i];
- gr[i] = temp;
- }
- }
- static void Main(string[] args)
- {
- Stipend[] gr1 = new Stipend[5];
- gr1[0] = new Stipend("Иванов", new double[] { 5.0, 4.0, 5.0, 5.0, 4.0 });
- gr1[1] = new Stipend("Петрова", new double[] { 3.0, 2.0, 4.0, 2.0, 2.0 });
- gr1[2] = new Stipend("Сидоров", new double[] { 5.0, 4.0, 4.0, 4.0, 5.0 });
- gr1[3] = new Stipend("Смирнова", new double[] { 3.0, 4.0, 3.0, 3.0, 4.0 });
- gr1[4] = new Stipend("Кузнецов", new double[] { 2.0, 4.0, 5.0, 3.0, 4.0 });
- Sort(gr1);
- Console.WriteLine("Первая группа:");
- for (int i = 0; i < gr1.Length; i++)
- {
- Console.WriteLine("Фамилия {0} \tСредний балл {1,4:f2} \tСтипендия {2}",
- gr1[i].name, gr1[i].avrg, gr1[i].yn);
- }
- Console.WriteLine();
- Stipend[] gr2 = new Stipend[5];
- Console.WriteLine("Вторая группа:");
- gr2[0] = new Stipend("Соколова", new double[] { 3.0, 2.0, 4.0, 5.0, 4.0 });
- gr2[1] = new Stipend("Попов", new double[] { 4.0, 2.0, 4.0, 5.0, 2.0 });
- gr2[2] = new Stipend("Лебедев", new double[] { 5.0, 2.0, 5.0, 5.0, 5.0 });
- gr2[3] = new Stipend("Иванова", new double[] { 3.0, 2.0, 3.0, 3.0, 4.0 });
- gr2[4] = new Stipend("Новиков", new double[] { 5.0, 3.0, 5.0, 4.0, 4.0 });
- Sort(gr2);
- for (int i = 0; i < gr2.Length; i++)
- {
- Console.WriteLine("Фамилия {0} \tСредний балл {1,4:f2} \tСтипендия {2}",
- gr2[i].name, gr2[i].avrg, gr2[i].yn);
- }
- Console.WriteLine();
- Stipend[] gr3 = new Stipend[5];
- Console.WriteLine("Третья группа:");
- gr3[0] = new Stipend("Лазарева", new double[] { 3.0, 4.0, 5.0, 5.0, 2.0 });
- gr3[1] = new Stipend("Медведева", new double[] { 4.0, 2.0, 2.0, 4.0, 3.0 });
- gr3[2] = new Stipend("Ершов", new double[] { 5.0, 3.0, 4.0, 4.0, 5.0 });
- gr3[3] = new Stipend("Смирнов", new double[] { 3.0, 4.0, 3.0, 5.0, 4.0 });
- gr3[4] = new Stipend("Орехова", new double[] { 2.0, 5.0, 4.0, 3.0, 4.0 });
- Sort(gr3);
- for (int i = 0; i < gr3.Length; i++)
- {
- Console.WriteLine("Фамилия {0} \tСредний балл {1,4:f2} \tСтипендия {2}",
- gr1[i].name, gr1[i].avrg, gr1[i].yn);
- }
- Console.ReadKey();
- }
- }
- /// III.6
- struct Question
- {
- public string answer;
- public int votes;
- public Question(string a)
- {
- votes = 0;
- answer = a;
- }
- }
- class Program
- {
- static void CountVotes(Question[] q, string a, ref int k, ref double v)
- {
- bool b = true;
- for (int i = 0; i < k; i++)
- {
- if (a == q[i].answer)
- {
- q[i].votes++;
- v++;
- b = false;
- break;
- }
- }
- if ((a != "-") && b)
- {
- q[k].answer = a;
- q[k].votes++;
- v++;
- k++;
- }
- }
- static void Sort(Question[] q)
- {
- int max = 0, imax = 0;
- for (int i = 0; i < 5; i++)
- {
- max = q[i].votes;
- imax = i;
- for (int j = i + 1; j < q.Length; j++)
- {
- if (q[j].votes > max)
- {
- max = q[j].votes;
- imax = j;
- }
- }
- Question temp;
- temp = q[i];
- q[i] = q[imax];
- q[imax] = temp;
- }
- }
- static void Print(Question[] q, ref double v, StreamWriter sw, string path)
- {
- double p = 0;
- for (int i = 0; i < 5; i++)
- {
- p = q[i].votes / v;
- Console.WriteLine("{0}. {1}\t {2:f2}%", i + 1, q[i].answer, p);
- sw.WriteLine("{0}. {1}\t {2:f2}%", i + 1, q[i].answer, p);
- }
- }
- static void Main(string[] args)
- {
- string path = "C:\\Users\\Камила\\Downloads\\jp.txt";
- StreamReader sr = new StreamReader(path,Encoding.GetEncoding(1251));
- string line;
- line = sr.ReadLine();
- int n = int.Parse(line);
- Question[] animal = new Question[n];
- Question[] trait = new Question[n];
- Question[] concept = new Question[n];
- double av = 0, tv = 0, cv = 0;
- int ak = 0, tk = 0, ck = 0;
- while ((line = sr.ReadLine()) != null)
- {
- string[] answers = line.Split('|');
- {
- CountVotes(animal, answers[0], ref ak, ref av);
- CountVotes(trait, answers[1], ref tk, ref tv);
- CountVotes(concept, answers[2], ref ck, ref cv);
- }
- }
- string path1 = "C:\\Users\\Камила\\Downloads\\jp1.txt";
- StreamWriter sw = new StreamWriter(path1);
- Sort(animal);
- Console.WriteLine("5 наиболее частых ответов на 1 вопрос:");
- Print(animal, ref av, sw, path1);
- Sort(trait);
- Console.WriteLine("5 наиболее частых ответов на 2 вопрос:");
- Print(trait, ref tv, sw, path1);
- Sort(concept);
- Console.WriteLine("5 наиболее частых ответов на 3 вопрос:");
- Print(concept, ref cv, sw, path1);
- sw.Close();
- Console.ReadKey();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement