Перевести код с Pascal на C#: задача о студентах и их предпочтениях

Узнай цену своей работы

Формулировка задачи:

Помогите пожалуйста перевести код на С#(как угодно), заранее спасибо.
Листинг программы
  1. const n=5; m=9;
  2. var student:array [1..n] of string;
  3. like:array[1..m] of record
  4. whom,who:string;
  5. end;
  6. i,j:integer; p:boolean;
  7. begin
  8. student[1]:='sasha';
  9. student[2]:='masha';
  10. student[3]:='dasha';
  11. student[4]:='pasha';
  12. student[5]:='natasha';
  13. like[1].who:='sasha'; like[1].whom:='masha';
  14. like[2].who:='sasha'; like[2].whom:='dasha';
  15. like[3].who:='sasha'; like[3].whom:='pasha';
  16. like[4].who:='sasha'; like[4].whom:='natasha';
  17. like[5].who:='masha'; like[5].whom:='sasha';
  18. like[6].who:='masha'; like[6].whom:='masha';
  19. like[7].who:='dasha'; like[7].whom:='masha';
  20. like[8].who:='pasha'; like[8].whom:='masha';
  21. like[9].who:='natasha'; like[9].whom:='masha';
  22. for i:=1 to n do begin
  23. p:=false;
  24. for j:=1 to m do
  25. if (like[j].who='sasha') and (like[j].whom=student[i]) then p:=true;
  26. if p=false then writeln(student[i]);
  27. end;
  28. end.

Решение задачи: «Перевести код с Pascal на C#: задача о студентах и их предпочтениях»

textual
Листинг программы
  1. using System;
  2.  
  3. namespace ConsoleApplication
  4. {
  5.     public struct Likeness
  6.     {
  7.         public string Whom { set; get; }
  8.         public string Who { set; get; }
  9.  
  10.         public Likeness(string whom, string who) : this() {
  11.             this.Whom = whom;
  12.             this.Who = who;
  13.         }
  14.     }
  15.  
  16.     public class Program
  17.     {
  18.         static void Main(string[] args) {
  19.             string[] student = { "Саша", "Маша", "Даша", "Паша", "Наташа" };
  20.             Likeness[] like = new Likeness[] {
  21.                 new Likeness("Маша", "Саша"),
  22.                 new Likeness("Даша", "Саша"),
  23.                 new Likeness("Паша", "Саша"),
  24.                 new Likeness("Наташа", "Саша"),
  25.                 new Likeness("Саша", "Маша"),
  26.                 new Likeness("Маша", "Маша"),
  27.                 new Likeness("Маша", "Даша"),
  28.                 new Likeness("Маша", "Паша"),
  29.                 new Likeness("Маша", "Наташа")
  30.             };
  31.  
  32.             bool p = false;
  33.             for (int i = 0; i < student.Length; i++) {
  34.                 p = false;
  35.                 for (int j = 0; j < like.Length; j++) {
  36.                     if (like[j].Who == "Саша" && like[j].Whom == student[i])
  37.                         p = true;
  38.                 }
  39.                 if (p == false)
  40.                     Console.WriteLine(student[i]);
  41.             }
  42.         }
  43.     }
  44. }

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

15   голосов , оценка 3.8 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы