По разделам

 

Решение задачи 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 Просмотров: 4448
Series 2 Просмотров: 2276
Series 3 Просмотров: 2038
Series 4 Просмотров: 2222
Series 5 Просмотров: 2096
Series 6 Просмотров: 2679
Series 7 Просмотров: 2938
Series 8 Просмотров: 3229
Series 9 Просмотров: 1915
Series 10 Просмотров: 2368
Series 11 Просмотров: 1783
Series 12 Просмотров: 2136
Series 13 Просмотров: 1560
Series 14 Просмотров: 1451
Series 15 Просмотров: 1743
Series 16 Просмотров: 2148
Series 17 Просмотров: 1961
Series 18 Просмотров: 2787
Series 19 Просмотров: 2494
Series 20 Просмотров: 1545
Series 21 Просмотров: 1713
Series 22 Просмотров: 1657
Series 23 Просмотров: 2058
Series 24 Просмотров: 1891
Series 25 Просмотров: 1458
Series 26 Просмотров: 1297
Series 27 Просмотров: 1227
Series 28 Просмотров: 1171
Series 29 Просмотров: 1194
Series 30 Просмотров: 1233
Series 31 Просмотров: 1188
Series 32 Просмотров: 1707
Series 33 Просмотров: 981
Series 34 Просмотров: 1030
Series 35 Просмотров: 1408
Series 36 Просмотров: 1520
Series 37 Просмотров: 950
Series 38 Просмотров: 1272
Series 39 Просмотров: 900
Series 40 Просмотров: 1249

Комментарии

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



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