Предмет: Информатика, автор: ilya470569888

Помогите составить краткий алгоритм по этому коду C++ пожалуйста (85 баллов)
#include
using namespace std;

int main() {
int n;
cin>>n;
int arr[n+1];
int p{};
while(cin>>arr[++p]);
int s{};
for(int i=1;i<=n;i++){
int x=arr[i];
int count=1;
while(x!=-1){
count++;
x=arr[x];
}
s=max(count,s);
}
cout< return 0;

Ответы

Автор ответа: BorzenKovskiy
1

Ответ:

#include <algorithm>

#include <array>

#include <iostream>

int main()

{

std::array<int, 6> arr{ 13, 90, 99, 5, 40, 80 };

std::cout « "Enter a value to search for and replace with: ";

int search{};

int replace{};

std::cin » search » replace;

// Проверка пользовательского ввода должна быть здесь

// std::find() возвращает итератор, указывающий на найденный элемент (или на конец контейнера).

// Мы сохраним его в переменной, используя автоматический вывод типа итератора

auto found{ std::find(arr.begin(), arr.end(), search) };

// Алгоритмы, которые не нашли то, что искали, возвращают итератор, указывающий на конец контейнера.

// Мы можем получить доступ к этому итератору, используя метод end()

if (found == arr.end())

{

std::cout « "Could not find " « search « '\n';

}

else

{

// Перезаписываем найденный элемент

*found = replace;

}

for (int i : arr)

{

std::cout « i « ' ';

}

std::cout « '\n';

return 0;

}

Похожие вопросы
Предмет: Химия, автор: Oksocoolamazing
Предмет: Английский язык, автор: Queen666
Нужно вставить нужные слова в текст :

Modern technology has brought about big improvements in communications, yet many people are worried (1) ___ using the lates computer technology. I'm ofter (2) ___ to meet people who still don't know what the "e" in e-mail stands for and they are too (3) ___ to ask. They thing one has to be skilled (4) __ computers to sen a message by e-mail but in fact, it is (5) __ thing in the world. It is also (6) __ to send an e-mail message (7) __ to send a "snail" message, which takes (8)___ longer. An e-mail message is only (9)__ more expensive than a local telephone call : on top of the call itself, you also have to pay a fee to your "server". If you send a letter (10)__ mail it will take two days to get there whereas an e-mail will not take (11)__ than a few seconds. When you become (12)__ to using the system you will be (13)__ at how much more (14)__ it is than other means of communication. Of course, before you have an access to e-mail you will need a fairly (15)__ compute, which be quite expensive.

Слова :
1) A. a for B. about C. at D. with as
2) A. surprising B. irritating C. surprised D. irritated
3) A. embrrassing B. embrasses C. tired D. tiring
4) A. about B. into C to D in
5) A. simplest B. the more simple C. simpler D. the simplest
6) A. cheaper B. more cheaper C. cheapest D. the cheaper
7) A. as B. Than C. that D. from
8) A. moch B. more C. as D. Lot
9) A. little B. slightly C. less D. least
10) A. second-hand B. low-paid C. part-time D. first-class
11) A. more long B. longest C. as long D. longer
12) A. capable B. accustomed C. clever D. good
Предмет: Физика, автор: Некит12111