По разделам

 

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


Дано целое число K, а также K наборов ненулевых целых чисел.
Каждый набор содержит не менее двух элементов, признаком его завершения является число 0. Найти количество наборов, элементы которых
возрастают.

Код (C/C++)

#include <stdio.h>
int main(void)
{
    int k;
    printf("K:");
    scanf("%i", &k);
 
    int count=0,ki,a=1,a1;
    for (ki=1; ki<=k; ++ki){
       printf(">");
       scanf("%i", &a);
       int check=1;
       while(a!=0){
            a1=a;
            printf(">");
            scanf("%i", &a);
            if ((a1>a)&&(a!=0)) check=0;
        }
    if (check)  count+=1;
    }
    printf("%i\n",count);
    return 0;
}

Код (Python)

import random

K = random.randrange(1,7)

print("K = ",K)

count_inc = 0
for i in range(0,K):
    x_prev = random.randrange(1,4)
    print(x_prev,end="; ")
    x = random.randrange(1,4)
    print(x,end="; ")
    if x > x_prev:
        flag = True
    else:
        flag = False
    while True:
        x_prev = x
        x = random.randrange(0,4)
        print(x,end="; ")
        if x == 0:
            break
        if not (flag and x > x_prev):
            flag = False
    print()
    if flag:
        count_inc += 1
print("Number of increasing series: ",count_inc)
									

Код (Pascal)

program Series36;
var
  K,Ki,A,A1,Count:Integer;
  Check:Boolean;
begin
 Write('K: ');
 Readln(K);
 Count:=0;
 for Ki:=1 to K do
  begin
   Write('A: ');
   Readln(A);
   Check:=True;
   repeat
    A1:=A;
    Write('A: ');
    Readln(A);
    if (A1>A) and (A<>0) then Check:=False;
   until A=0;
    Writeln('---');
   If Check then Count:=Count+1;
  end;
  Writeln(Count);
end.
									




Series. Абрамян
Series 1 Просмотров: 4390
Series 2 Просмотров: 2232
Series 3 Просмотров: 2006
Series 4 Просмотров: 2171
Series 5 Просмотров: 2051
Series 6 Просмотров: 2613
Series 7 Просмотров: 2893
Series 8 Просмотров: 3198
Series 9 Просмотров: 1864
Series 10 Просмотров: 2320
Series 11 Просмотров: 1749
Series 12 Просмотров: 2087
Series 13 Просмотров: 1519
Series 14 Просмотров: 1417
Series 15 Просмотров: 1702
Series 16 Просмотров: 2115
Series 17 Просмотров: 1915
Series 18 Просмотров: 2749
Series 19 Просмотров: 2442
Series 20 Просмотров: 1487
Series 21 Просмотров: 1681
Series 22 Просмотров: 1630
Series 23 Просмотров: 2017
Series 24 Просмотров: 1854
Series 25 Просмотров: 1422
Series 26 Просмотров: 1259
Series 27 Просмотров: 1198
Series 28 Просмотров: 1143
Series 29 Просмотров: 1163
Series 30 Просмотров: 1199
Series 31 Просмотров: 1157
Series 32 Просмотров: 1674
Series 33 Просмотров: 951
Series 34 Просмотров: 996
Series 35 Просмотров: 1378
Series 36 Просмотров: 1485
Series 37 Просмотров: 919
Series 38 Просмотров: 1236
Series 39 Просмотров: 876
Series 40 Просмотров: 1213

Комментарии

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



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