По разделам

 

Решение задачи 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 Просмотров: 4664
Series 2 Просмотров: 2401
Series 3 Просмотров: 2189
Series 4 Просмотров: 2364
Series 5 Просмотров: 2238
Series 6 Просмотров: 2855
Series 7 Просмотров: 3066
Series 8 Просмотров: 3386
Series 9 Просмотров: 2059
Series 10 Просмотров: 2502
Series 11 Просмотров: 1896
Series 12 Просмотров: 2269
Series 13 Просмотров: 1666
Series 14 Просмотров: 1577
Series 15 Просмотров: 1889
Series 16 Просмотров: 2290
Series 17 Просмотров: 2086
Series 18 Просмотров: 2933
Series 19 Просмотров: 2629
Series 20 Просмотров: 1667
Series 21 Просмотров: 1815
Series 22 Просмотров: 1803
Series 23 Просмотров: 2243
Series 24 Просмотров: 2021
Series 25 Просмотров: 1557
Series 26 Просмотров: 1416
Series 27 Просмотров: 1323
Series 28 Просмотров: 1279
Series 29 Просмотров: 1302
Series 30 Просмотров: 1336
Series 31 Просмотров: 1313
Series 32 Просмотров: 1854
Series 33 Просмотров: 1098
Series 34 Просмотров: 1148
Series 35 Просмотров: 1530
Series 36 Просмотров: 1627
Series 37 Просмотров: 1059
Series 38 Просмотров: 1384
Series 39 Просмотров: 996
Series 40 Просмотров: 1373

Комментарии

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



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