По разделам

 

Решение задачи Series 31


Даны целые числа K, N, а также K наборов целых чисел по N элементов в каждом наборе. Найти количество наборов, содержащих число 2.
Если таких наборов нет, то вывести 0.

Код (C/C++)

#include <stdio.h>
int main(void)
{
    int k,n;
    printf("K:");
    scanf("%i", &k);
 
    printf("N:");
    scanf("%i", &n);
 
    int ki,ni, a,f=0,s=0;
    for (ki=1; ki<=k; ++ki, f=0){
        for (ni=1; ni<=n; ++ni){
            printf("%i:%i>",ki,ni);
            scanf("%i", &a);
            if (a==2) f=1;
        }
    s+=f;
 
    }
    printf("%i\n",s);
    return 0;
}

Код (Python)

import random

N = random.randrange(1,7)
K = random.randrange(1,7)

print("N = ",N)
print("K = ",K)
S = 0
for i in range(0,K):
    flag = False
    for j in range(0,N):
        x = random.randrange(0,4)
        print(x,end="; ")
        if x == 2:
            flag = True
    if flag:
        S += 1
    print()

print()
print("Количество наборов, содержащих 2:",S)
									

Код (Pascal)

program Series31;
var
  K,N,Ni,Ki,S,A:Integer;
  Check: Boolean;
begin
 
 Write('N: ');
 Readln(N);
 
 Write('K: ');
 Readln(K);
 
 S:=0;
 for Ki:=1 to K do
  begin
   check:=FALSE;
   for Ni:=1 to N do
    begin
     write('Введите ',Ni,' число из ',Ki ,' набора :');
     Readln(A);
     if A=2 then check:=TRUE;
    end;
   if check then S:=S+1;
  end;
 writeln(S);
 readln;
end.
									




Series. Абрамян
Series 1 Просмотров: 4443
Series 2 Просмотров: 2268
Series 3 Просмотров: 2035
Series 4 Просмотров: 2217
Series 5 Просмотров: 2091
Series 6 Просмотров: 2674
Series 7 Просмотров: 2933
Series 8 Просмотров: 3228
Series 9 Просмотров: 1914
Series 10 Просмотров: 2365
Series 11 Просмотров: 1775
Series 12 Просмотров: 2130
Series 13 Просмотров: 1557
Series 14 Просмотров: 1447
Series 15 Просмотров: 1734
Series 16 Просмотров: 2146
Series 17 Просмотров: 1955
Series 18 Просмотров: 2784
Series 19 Просмотров: 2489
Series 20 Просмотров: 1540
Series 21 Просмотров: 1711
Series 22 Просмотров: 1655
Series 23 Просмотров: 2055
Series 24 Просмотров: 1886
Series 25 Просмотров: 1453
Series 26 Просмотров: 1290
Series 27 Просмотров: 1222
Series 28 Просмотров: 1171
Series 29 Просмотров: 1192
Series 30 Просмотров: 1231
Series 31 Просмотров: 1184
Series 32 Просмотров: 1703
Series 33 Просмотров: 979
Series 34 Просмотров: 1027
Series 35 Просмотров: 1406
Series 36 Просмотров: 1516
Series 37 Просмотров: 948
Series 38 Просмотров: 1268
Series 39 Просмотров: 897
Series 40 Просмотров: 1243

Комментарии

Чтобы написать комментарии вам нужно войти в систему или зарегистрироваться



Заявка на расчет