По разделам

 

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


Дано целое число N (> 1) и набор из N вещественных чисел. Если
данный набор образует убывающую последовательность, то вывести 0;
в противном случае вывести номер первого числа, нарушающего закономерность.

Код (C/C++)

# include <iostream>
# include <windows.h>
# include <cmath>
# include <iomanip>
# include <fstream>
 
using namespace std;
 
int main ()
 
{
  SetConsoleCP(1251);
  SetConsoleOutputCP(1251);
 
 
  ifstream in ("Series22.txt");
  double a;
  double a_;
  in >> a_;
  cout << "Дан набор вещественных чисел: " ;
  cout << a_ << " ";
  int i = 1;
  int n = 0;
  while (in >> a ) {
        cout << a << " " ;
        ++i;
        if (a >= a_ && n == 0) n = i;
        a_ = a;
  }
  in.close ();
  cout << endl;
  if (n == 0) cout << "Последовательность убывающая." << endl;
  else cout << "Номер первого числа, нарушающего убывающую последовательность: " <<  n << endl;
 
  system ("pause");
  return 0;
}

Код (Python)

import random

N = random.randrange(2,20)
print("N = ",N)

#x = N
x = random.randrange(1,10)
x_prev = x
flag = True
for i in range(1,N):
    #x = N-i
    x = random.randrange(1,10)
    if x_prev <= x:
        flag = False
        #break
    print(x_prev,end="; ")
    x_prev = x
print(x)

print("Result = ",flag)
									

Код (Pascal)

program Series22;
var
  i,N,Num,Num1,El :Integer;
  b:boolean;
begin
 b:=TRUE;
 El:=0;
 Write('N:');
 Readln(N);
 
 for i:=1 to N do
   begin
    write('Введите ',i,' элемент последовательности :');
    Readln(Num);
    if (((Num1<Num) and (i<>1)) and b) then
     begin
      El:=i;
      b:=FALSE;
     end;
     Num1:=Num;
   end;
  Writeln(El);
end.
									

Дополнительно

n = int(input())
temp = float(input())
t = temp
b = True
idx = 0
for i in range(n - 1):
    temp = float(input())
    if temp > t and b:
        b = False
        idx = i + 2 # допустим, что индексация начинается с 1
    t = temp
if b:
    print(0)
else:
    print(idx)
									



Series. Абрамян
Series 1 Просмотров: 4442
Series 2 Просмотров: 2267
Series 3 Просмотров: 2034
Series 4 Просмотров: 2217
Series 5 Просмотров: 2091
Series 6 Просмотров: 2672
Series 7 Просмотров: 2933
Series 8 Просмотров: 3227
Series 9 Просмотров: 1914
Series 10 Просмотров: 2363
Series 11 Просмотров: 1774
Series 12 Просмотров: 2129
Series 13 Просмотров: 1556
Series 14 Просмотров: 1446
Series 15 Просмотров: 1733
Series 16 Просмотров: 2145
Series 17 Просмотров: 1955
Series 18 Просмотров: 2783
Series 19 Просмотров: 2489
Series 20 Просмотров: 1539
Series 21 Просмотров: 1710
Series 22 Просмотров: 1654
Series 23 Просмотров: 2054
Series 24 Просмотров: 1885
Series 25 Просмотров: 1453
Series 26 Просмотров: 1289
Series 27 Просмотров: 1221
Series 28 Просмотров: 1170
Series 29 Просмотров: 1190
Series 30 Просмотров: 1230
Series 31 Просмотров: 1183
Series 32 Просмотров: 1702
Series 33 Просмотров: 978
Series 34 Просмотров: 1026
Series 35 Просмотров: 1405
Series 36 Просмотров: 1515
Series 37 Просмотров: 948
Series 38 Просмотров: 1267
Series 39 Просмотров: 896
Series 40 Просмотров: 1242

Комментарии

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



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