Перевести код с Pascal на C#: задача о студентах и их предпочтениях
Формулировка задачи:
Помогите пожалуйста перевести код на С#(как угодно), заранее спасибо.
Листинг программы
- const n=5; m=9;
- var student:array [1..n] of string;
- like:array[1..m] of record
- whom,who:string;
- end;
- i,j:integer; p:boolean;
- begin
- student[1]:='sasha';
- student[2]:='masha';
- student[3]:='dasha';
- student[4]:='pasha';
- student[5]:='natasha';
- like[1].who:='sasha'; like[1].whom:='masha';
- like[2].who:='sasha'; like[2].whom:='dasha';
- like[3].who:='sasha'; like[3].whom:='pasha';
- like[4].who:='sasha'; like[4].whom:='natasha';
- like[5].who:='masha'; like[5].whom:='sasha';
- like[6].who:='masha'; like[6].whom:='masha';
- like[7].who:='dasha'; like[7].whom:='masha';
- like[8].who:='pasha'; like[8].whom:='masha';
- like[9].who:='natasha'; like[9].whom:='masha';
- for i:=1 to n do begin
- p:=false;
- for j:=1 to m do
- if (like[j].who='sasha') and (like[j].whom=student[i]) then p:=true;
- if p=false then writeln(student[i]);
- end;
- end.
Решение задачи: «Перевести код с Pascal на C#: задача о студентах и их предпочтениях»
textual
Листинг программы
- using System;
- namespace ConsoleApplication
- {
- public struct Likeness
- {
- public string Whom { set; get; }
- public string Who { set; get; }
- public Likeness(string whom, string who) : this() {
- this.Whom = whom;
- this.Who = who;
- }
- }
- public class Program
- {
- static void Main(string[] args) {
- string[] student = { "Саша", "Маша", "Даша", "Паша", "Наташа" };
- Likeness[] like = new Likeness[] {
- new Likeness("Маша", "Саша"),
- new Likeness("Даша", "Саша"),
- new Likeness("Паша", "Саша"),
- new Likeness("Наташа", "Саша"),
- new Likeness("Саша", "Маша"),
- new Likeness("Маша", "Маша"),
- new Likeness("Маша", "Даша"),
- new Likeness("Маша", "Паша"),
- new Likeness("Маша", "Наташа")
- };
- bool p = false;
- for (int i = 0; i < student.Length; i++) {
- p = false;
- for (int j = 0; j < like.Length; j++) {
- if (like[j].Who == "Саша" && like[j].Whom == student[i])
- p = true;
- }
- if (p == false)
- Console.WriteLine(student[i]);
- }
- }
- }
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д