Помощь - Поиск - Пользователи - Календарь
Полная версия: Множества
Форум «Всё о Паскале» > Pascal, Object Pascal > Задачи
snopy
Помогите пожайлуста найти ошибку.
В институте имеются секции по следующим видам спорта:
лыжи, коньки, хоккей, футбол, регби, самбо. Известны виды спорта, которыми занимаются учащиеся каждой группы. Количество групп -4. Требуется построить и распечатать множество видов спорта:
1) которыми занимаются хотя бы в одной группе;
2) которыми не занимаются во всех группах.

Код

const
    n=2;
type
   Sport=(Skis,Skates,hoccey,football,regbi,sambo);
   vid=set of sport;
   zanytia=array[1..n] of vid;
var
   M1:zanytia;
   x:sport;
a,b,c,xm1:vid;
i,j,m,iw:byte;
BEGIN
    for i:=1 to n do
        begin
             xm1:=[];
              writeln('Vvedite nomera sportov ',i:2,'-go sporta');
                     repeat
                          read(iw);
                                  case iw of
                                           1:x:=skis;
                                           2:x:=skates;
                                           3:x:=hoccey;
                                           4:x:=football;
                                           5:x:=regbi;
                                           6:x:=sambo
                                           else
                                              writeln('Nomera sportov 1..6')
                                           end;
                                           xm1:=xm1+[x];
                                           until eoln;
                                           m1[i]:=xm1;
                                           end;
                                           c:=[Skis,Skates,hoccey,football,regbi,sambo];
                                           A:=m1[1]+m1[2];
                                           B:=B-A;
                                                  for i:=1 to n do
                                                      begin
                                                           case i of
                                                                    1:writeln('kotorymi zanimautcy xotyby v odnoy grupe: ');
                                                                    2:writeln('kotorymi ne zanimautcy vo vsech gruppax: ');
                                                  end;
                                           for x:=skis to sambo do
                                               if x in a then
                                                   case x of
                                                            Skis:write('Skis')
                                                          Skates:write('Skates')
                                                          hoccey:write('hoccey')
                                                        football:write('football')
                                                           regbi:write('regbi')
                                                           sambo:write('sambo')
                                                    end;
                                                if i:=1 then a:=b
                                                        else
                                                            a:=c; writeln;
end;
End.
volvo
Тебе компилятор скажет где ошибки... Нажми F9 для этого... Вот когда ВСЕ синтаксические ошибки исправишь - приходи...
snopy
Вот исправил только мне кажется где то всё равно ошибка
Код

const
    n=4;
type
   Sport=(Skis,Skates,hoccey,football,regbi,sambo);
   vid=set of sport;
   zanytia=array[1..n] of vid;
var
   M1:zanytia;
   x:sport;
a,b,c,xm1:vid;
i,j,m,iw:byte;
BEGIN
    for i:=1 to n do
        begin
             xm1:=[];
              writeln('Vvedite nomera sportov ',i:2,'-go sporta');
                     repeat
                          read(iw);
                                  case iw of
                                           1:x:=skis;
                                           2:x:=skates;
                                           3:x:=hoccey;
                                           4:x:=football;
                                           5:x:=regbi;
                                           6:x:=sambo
                                           else
                                              writeln('Nomera sportov 1..6')
                                           end;
                                           xm1:=xm1+[x];
                                           until eoln;
                                           m1[i]:=xm1;
                                           end;
                                           c:=[Skis,Skates,hoccey,football,regbi,sambo];
                                           A:=m1[1]+m1[2];
                                           B:=B-A;
                                                  for i:=1 to n do
                                                      begin
                                                           case i of
                                                                    1:writeln('kotorymi zanimautcy xotyby v odnoy grupe: ');
                                                                    2:writeln('kotorymi ne zanimautcy vo vsech gruppax: ');
                                                  end;
                                           for x:=skis to sambo do
                                               if x in a then
                                                   case x of
                                                            Skis:write('Skis');
                                                          Skates:write('Skates');
                                                          hoccey:write('hoccey');
                                                        football:write('football');
                                                           regbi:write('regbi');
                                                           sambo:write('sambo');
                                                     end;
                                                if i=1 then a:=b
                                                        else
                                                            a:=c; writeln;
end;
End.
snopy
Пожайлуста помогите
snopy
ашёл ещё ошибку у себя. Помогите найти другие
Код

const
    n=4;
type
   Sport=(Skis,Skates,hoccey,football,regbi,sambo);
   vid=set of sport;
   zanytia=array[1..n] of vid;
var
   M1:zanytia;
   x:sport;
a,b,c,xm1:vid;
i,j,m,iw:byte;
BEGIN
    for i:=1 to n do
        begin
             xm1:=[];
              writeln('Vvedite nomera sportov ',i:2,'-go sporta');
                     repeat
                          read(iw);
                                  case iw of
                                           1:x:=skis;
                                           2:x:=skates;
                                           3:x:=hoccey;
                                           4:x:=football;
                                           5:x:=regbi;
                                           6:x:=sambo
                                           else
                                              writeln('Nomera sportov 1..6')
                                           end;
                                           xm1:=xm1+[x];
                                           until eoln;
                                           m1[i]:=xm1;
                                           end;
                                           c:=[Skis,Skates,hoccey,football,regbi,sambo];
                                           A:=m1[1]+m1[2]+m1[3]+m1[4];
                                           B:=B-A;
                                                  for i:=1 to n do
                                                      begin
                                                           case i of
                                                                    1:writeln('kotorymi zanimautcy xotyby v odnoy grupe: ');
                                                                    2:writeln('kotorymi ne zanimautcy vo vsech gruppax: ');
                                                  end;
                                           for x:=skis to sambo do
                                               if x in a then
                                                   case x of
                                                            Skis:write('Skis');
                                                          Skates:write('Skates');
                                                          hoccey:write('hoccey');
                                                        football:write('football');
                                                           regbi:write('regbi');
                                                           sambo:write('sambo');
                                                     end;
                                                if i=1 then a:=b
                                                        else
                                                            a:=c; writeln;
end;
End.
Malice
Цитата
c:=[Skis,Skates,hoccey,football,regbi,sambo];
A:=m1[1]+m1[2]+m1[3]+m1[4];
B:=B-A;

У тебя значение B не определено, а ты из него вычитаешь. Логичней было б B:=C-A;
Да и цикл следующий до n зачем ? До 2-х вроде надо.
snopy
Цитата(Malice @ 11.12.2007 20:49) *

У тебя значение B не определено, а ты из него вычитаешь. Логичней было б B:=C-A;


так тоже не получается

Добавлено через 3 мин.
Вот ещё додумал только с выводом проблема там где надо чтоб писалось которыми не занимаются во всех группах это пишется правильно только ниже идёт две строчки перечесления спортов
Код

const
    n=4;
type
   Sport=(Skis,Skates,hoccey,football,regbi,sambo);
   vid=set of sport;
   zanytia=array[1..n] of vid;
var
   M1:zanytia;
   x:sport;
a,b,c,xm1:vid;
i,j,m,iw:byte;
BEGIN
    for i:=1 to n do
        begin
             xm1:=[];
              writeln('Vvedite nomera sportov ',i:2,'-go sporta');
                     repeat
                          read(iw);
                                  case iw of
                                           1:x:=skis;
                                           2:x:=skates;
                                           3:x:=hoccey;
                                           4:x:=football;
                                           5:x:=regbi;
                                           6:x:=sambo
                                           else
                                              writeln('Nomera sportov 1..6')
                                           end;
                                           xm1:=xm1+[x];
                                           until eoln;
                                           m1[i]:=xm1;
                                           end;
                                           c:=[Skis,Skates,hoccey,football,regbi,sambo];
                                           A:=m1[1]+m1[2]+m1[3]+m1[4];
                                           B:=C-A;
                                                  for i:=1 to n do
                                                      begin
                                                           case i of
                                                                    1:writeln('kotorymi zanimautcy xotyby v odnoy grupe: ');
                                                                    2:writeln('kotorymi ne zanimautcy vo vsech gruppax: ');
                                                  end;
                                           for x:=skis to sambo do
                                               if x in a then
                                                   case x of
                                                            Skis:write('Skis');
                                                          Skates:write(' Skates');
                                                          hoccey:write(' hoccey');
                                                        football:write(' football');
                                                           regbi:write(' regbi');
                                                           sambo:write(' sambo');
                                                     end;
                                                if i=1 then a:=b
                                                       else
                                                           a:=c;
                                             writeln;
end;
End.





Добавлено через 5 мин.
Malice спасибо тебе за то что указал на цикл. Теперь всё работает
Это текстовая версия — только основной контент. Для просмотра полной версии этой страницы, пожалуйста, нажмите сюда.