Вопрос задан 28.02.2019 в 07:13. Предмет Информатика. Спрашивает Астахов Иван.

В файле записаны данные о результатах сдачи экзамена. Каждая строка содержит фамилию, имя и

количество баллов, разделенные пробелами: <Фамилия> <Имя> <Количество баллов> Вывести в другой файл данные учеников, которые получили больше 80 баллов. Список должен быть отсортирован по убыванию балла. Формат выходных данных: П. Иванов 98 И. Петров 96 ...
0 0
Перейти к ответам

Ответы на вопрос

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Косянчук Павло.
// PascalABC.NET 3.2, сборка 1449 от 23.05.2017
// Внимание! Если программа не работает, обновите версию!

type
  R=(string,integer);

begin
  var a:=ReadAllLines('input.txt');
  var L:=new List<R>;
  foreach var s in a do begin
    var w:=s.ToWords.ToArray;
    if w[2]>'80' then L+=(w[1][1]+'. '+w[0],w[2].ToInteger);
    end;
  var f:=OpenWrite('output.txt');
  L.OrderByDescending(x->x[1]).ForEach(x->Writeln(f,x[0],' ',x[1]));
  f.Close
end.
0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

To solve this task, you can write a program that reads the data from the input file, filters out the students who scored more than 80 points, sorts them in descending order based on their scores, and then writes the filtered and sorted data to the output file.

Here's an example of how you can achieve this in Python:

```python # Read the data from the input file with open('input.txt', 'r') as file: data = file.readlines()

# Filter out the students who scored more than 80 points filtered_data = [] for line in data: last_name, first_name, score = line.split() if int(score) > 80: filtered_data.append((last_name, first_name, int(score)))

# Sort the filtered data in descending order based on scores sorted_data = sorted(filtered_data, key=lambda x: x[2], reverse=True)

# Write the filtered and sorted data to the output file with open('output.txt', 'w') as file: for student in sorted_data: file.write(f'{student[0]} {student[1]} {student[2]}\n') ```

Make sure to replace `'input.txt'` with the actual name of your input file and `'output.txt'` with the desired name of your output file.

This program reads the data from the input file line by line, splits each line into last name, first name, and score, and checks if the score is greater than 80. If it is, the student's data is added to the `filtered_data` list as a tuple. Then, the `filtered_data` list is sorted in descending order based on the scores using the `sorted()` function and a lambda function as the key. Finally, the sorted data is written to the output file line by line.

Please let me know if you need any further assistance!

0 0

Топ вопросов за вчера в категории Информатика

Последние заданные вопросы в категории Информатика

Задать вопрос