IPB
ЛогинПароль:

> Прочтите прежде чем задавать вопрос!

1. Заголовок темы должен быть информативным. В противном случае тема удаляется ...
2. Все тексты программ должны помещаться в теги [code=pas] ... [/code].
3. Прежде чем задавать вопрос, см. "FAQ", если там не нашли ответа, воспользуйтесь ПОИСКОМ, возможно такую задачу уже решали!
4. Не предлагайте свои решения на других языках, кроме Паскаля (исключение - только с согласия модератора).
5. НЕ используйте форум для личного общения, все что не относится к обсуждению темы - на PM!
6. Одна тема - один вопрос (задача)
7. Проверяйте программы перед тем, как разместить их на форуме!!!
8. Спрашивайте и отвечайте четко и по существу!!!

2 страниц V < 1 2  
 Ответить  Открыть новую тему 
> Задача на логику
Michael_Rybak
сообщение 23.05.2008 2:25
Сообщение #21


Michael_Rybak
*****

Группа: Модераторы
Сообщений: 1 046
Пол: Мужской
Реальное имя: Michael_Rybak

Репутация: -  32  +


я предполагал, что is_enemy[] - двумерный массив 6х6, такой, что is_enemy[x, y] = true тогда и только тогда, когда депутаты номер х и у - враги.

фрагмент реального кода для депутата с будет выглядеть так:

               if (c = a) and (is_enemy[3,1]) the inc(c_enemies);
if (c = b) and (is_enemy[3,2]) the inc(c_enemies);
if (c = d) and (is_enemy[3,4]) the inc(c_enemies);
if (c = e) and (is_enemy[3,5]) the inc(c_enemies);
if (c = f) and (is_enemy[3,6]) the inc(c_enemies);


а вот в этом месте нужно вывести результат:

if f_enemies > m then continue;
//вот здесь
end;


вывод результата будет такой: выводишь 6 строк вида "депутата Х помещаем в палату У".
 Оффлайн  Профиль  PM 
 К началу страницы 
+ Ответить 
Tenshi
сообщение 23.05.2008 7:02
Сообщение #22


Новичок
*

Группа: Пользователи
Сообщений: 20
Пол: Мужской
Реальное имя: Artem

Репутация: -  0  +


переработанный код, но фсе равно не рабочий =(
 program omg;

var
is_enemy:array [1..6,1..6] of integer;
a,b,c,d,e,f,m:integer;
a_enemies: integer;
b_enemies: integer;
c_enemies: integer;
d_enemies: integer;
e_enemies: integer;
f_enemies: integer;
procedure sortirovka;
begin
for a:=1 to 2 do
for b:=1 to 2 do
for c:=1 to 2 do
for d:=1 to 2 do
for e:=1 to 2 do
for f:=1 to 2 do begin
a_enemies:=0;
if (a = b) and (is_enemy[1,2]) the inc(a_enemies);
if (a = c) and (is_enemy[1,3]) the inc(a_enemies);
if (a = d) and (is_enemy[1,4]) the inc(a_enemies);
if (a = e) and (is_enemy[1,5]) the inc(a_enemies);
if (a = f) and (is_enemy[1,6]) the inc(a_enemies);
if a_enemies > m then continue;
b_enemies:=0;
if (b = a) and (is_enemy[2,1]) the inc(b_enemies);
if (b = c) and (is_enemy[2,3]) the inc(b_enemies);
if (b = d) and (is_enemy[2,4]) the inc(b_enemies);
if (b = e) and (is_enemy[2,5]) the inc(b_enemies);
if (b = f) and (is_enemy[2,6]) the inc(b_enemies);
if b_enemies > m then continue;
c_enemies:=0;
if (c = a) and (is_enemy[3,1]) the inc(c_enemies);
if (c = b) and (is_enemy[3,2]) the inc(c_enemies);
if (c = d) and (is_enemy[3,4]) the inc(c_enemies);
if (c = e) and (is_enemy[3,5]) the inc(c_enemies);
if (c = f) and (is_enemy[3,6]) the inc(c_enemies);
if c_enemies > m then continue;
c_enemies:=0;
if (d = a) and (is_enemy[4,1]) the inc(d_enemies);
if (d = b) and (is_enemy[4,2]) the inc(d_enemies);
if (d = c) and (is_enemy[4,3]) the inc(d_enemies);
if (d = e) and (is_enemy[4,5]) the inc(d_enemies);
if (d = f) and (is_enemy[4,6]) the inc(d_enemies);
if d_enemies > m then continue;
e_enemies:=0;
if (e = a) and (is_enemy[5,1]) the inc(e_enemies);
if (e = b) and (is_enemy[5,2]) the inc(e_enemies);
if (e = c) and (is_enemy[5,3]) the inc(e_enemies);
if (e = d) and (is_enemy[5,4]) the inc(e_enemies);
if (e = f) and (is_enemy[5,6]) the inc(e_enemies);
if e_enemies > m then continue;
f_enemies:=0;
if (f = a) and (is_enemy[6,1]) the inc(f_enemies);
if (f = b) and (is_enemy[6,2]) the inc(f_enemies);
if (f = c) and (is_enemy[6,3]) the inc(f_enemies);
if (f = e) and (is_enemy[6,5]) the inc(f_enemies);
if (f = d) and (is_enemy[6,4]) the inc(f_enemies);
if f_enemies > m then continue;
if a_enemies>m then writeln ('Pomeshaem deputata A v palatu 2');
if b_enemies>m then writeln ('Pomeshaem deputata B v palatu 2');
if c_enemies>m then writeln ('Pomeshaem deputata C v palatu 2');
if d_enemies>m then writeln ('Pomeshaem deputata D v palatu 2');
if e_enemies>m then writeln ('Pomeshaem deputata E v palatu 2');
if f_enemies>m then writeln ('Pomeshaem deputata F v palatu 2')
end;
begin
Writeln ('Kolichestvo vragov m: ',m);
Readln (m);
Sortirovka;
Writeln ('The end');
end.
 Оффлайн  Профиль  PM 
 К началу страницы 
+ Ответить 
klem4
сообщение 23.05.2008 10:59
Сообщение #23


Perl. Just code it!
******

Группа: Модераторы
Сообщений: 4 100
Пол: Мужской
Реальное имя: Андрей

Репутация: -  44  +


const
n = 6;
type
TEnemies = set of byte;
TRelationship = array [1..n] of TEnemies;

function Intersect(const i, j, k: byte; const
iSet, jSet, kSet: TEnemies): boolean;
begin
Intersect := (i in jSet + kSet) or (j in iSet + kSet) or (k in iSet + jSet);
end;

var
r: TRelationship = (
([]), // враги первого (пусто в данном случае)
([4]), // враги второго
([4, 5]), // 3
([3, 2]), // 4
([3]), // 5
([]) // 6
);

i, j, k, l, id: byte;
idx: array [1..3] of byte;

begin
for i := 1 to n - 2 do
for j := i + 1 to n - 1 do
for k := j + 1 to n do
if not Intersect(i, j, k, r[i], r[j], r[k]) then begin
id := 0;
for l := 1 to n do
if (l <> i) and (l <> j) and (l <> k) then begin
inc(id); idx[id] := l;
end;
if not Intersect(idx[1], idx[2], idx[3], r[idx[1]], r[idx[2]], r[idx[3]]) then
writeln('Group A: (', i, ',', j, ',', k,
') Group B: (', idx[1], ',', idx[2], ',', idx[3], ')');
end;
end.


Сообщение отредактировано: klem4 - 23.05.2008 11:04


--------------------
perl -e 'print for (map{chr(hex)}("4861707079204E6577205965617221"=~/(.{2})/g)), "\n";'
 Оффлайн  Профиль  PM 
 К началу страницы 
+ Ответить 
Tenshi
сообщение 23.05.2008 11:13
Сообщение #24


Новичок
*

Группа: Пользователи
Сообщений: 20
Пол: Мужской
Реальное имя: Artem

Репутация: -  0  +


Всем Спасибо.
За курсовую получил максимум, хоть и решение было неверное, препод поставил за логику good.gif
 Оффлайн  Профиль  PM 
 К началу страницы 
+ Ответить 

2 страниц V < 1 2
 Ответить  Открыть новую тему 
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0

 



- Текстовая версия 18.07.2025 17:36
Хостинг предоставлен компанией "Веб Сервис Центр" при поддержке компании "ДокЛаб"