RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-444246

bdc1's questions

Martin Hope
bdc1
Asked: 2022-09-02 17:38:35 +0000 UTC

如何通过 onClick React js 对列进行排序?

  • 1

我需要对 2 列进行排序。

  1. 编号(1-200)
  2. 职称(AZ)

我怎么能用 onClick 做到这一点?

现在我正在排序,但是我无法以任何方式控制它,粗略地说,我在不按下按钮的情况下调用该函数,并且该列已经排序。

我将不胜感激任何帮助。

// Home.js
import React from "react";
import "./Home.css";
import { Link } from "react-router-dom";

export default class Home extends React.Component {
  // Constructor
  constructor(props) {
    super(props);

    this.state = {
      sortItemsTitle: [],
      sortItemsID: [],
      items: [],
    };
  }

  componentDidMount = () => {
    this.apiFetch();
  };

  //Fetch data from API
  apiFetch = () => {
    return fetch("https://jsonplaceholder.typicode.com/todos")
    .then((res) => res.json())
    .then((json) => {
      this.setState({
        items: json,
      });
    });
  };

  // Sort Title (A-Z)
  setSortedItemsTitle = () => {
    // const sorted = items.sort((a, b) => a.title.localeCompare(b.title));
    const { items } = this.state;
    const sortedTitle = items.sort((a,b) => {
      if (a.title < b.title) {
        return -1;
      }
      if (a.title > b.title) {
        return 1;
      }
      return 0;
    })
    console.log(sortedTitle);
  };
  
  // Sort ID (1-200)
  setSortedItemsID = () => {
    const { items } = this.state;
    const sortedID = items.sort((a, b) => {
      if (a.id < b.id) {
        return items.direction === 'ascending' ? -1 : 1;
      }
      if (a.id > b.id) {
        return items.direction === 'ascending' ? 1 : -1;
      }
      return 0;
    })
    console.log(sortedID);
  };

  render() {
    const { items } = this.state;
    return (
      <div>
        <h1>Home Page</h1>
        <table>
          <thead>
            <tr>
              <th>View Normal</th>
              <th>Group By UserID</th>
            </tr>
          </thead>
          <thead>
            <tr>
              <th>
                ID
                <button type="button" onClick={() => this.setSortedItemsID()}>⬇️</button>
                </th>
              <th>
                User ID
                </th>
              <th>
                Title
                <button type="button" onClick={() => this.setSortedItemsTitle()}>⬇️</button>
                </th>
              <th>
                Action
              </th>
            </tr>
          </thead>
          <tbody>
            {items.map((item) => (
              <tr key={item.id + item.title}>
                <td>{item.id}</td>
                <td>{item.userId}</td>
                <td>{item.title}</td>
                <td>
                  <Link target="self" to={`/details/${item.id}`}>
                    View Details
                  </Link>
                </td>
              </tr>
            ))}
          </tbody>
        </table>
      </div>
    );
  }
}
javascript
  • 1 个回答
  • 18 Views
Martin Hope
bdc1
Asked: 2022-08-31 17:22:03 +0000 UTC

如何通过 id 发出 GET 请求?

  • 0

我有一个 API 请求,我怎样才能使它显示特定 ID 所需的卡片?

我尝试将 url ${id} 添加到 API,但它不起作用,我需要帮助。

我的代码:

// Default.js
import React from "react";
import { Link } from "react-router-dom";

class Details extends React.Component {
  // Constructor
  constructor(props) {
    super(props);

    this.state = {
      items: [],
    };
  }

    componentDidMount = () => {
        return fetch(`https://jsonplaceholder.typicode.com/todos`)
        .then((res) => res.json())
        .then((json) => {
          this.setState({
            items: json,
          });
        });
    };
    render() {
      const { items } = this.state;
        return (
            <div>
              {items.map((item) => {
                return (
                  <div key={item.id}>
                    <div>
                      <h1>Details Page</h1>
                      <p>
                        <strong>Status:</strong> {item.status}
                      </p>
                      <p>
                        <strong>ID:</strong> {item.id}
                      </p>
                      <p>
                        <strong>Title:</strong> {item.title}
                      </p>
                      <p>
                        <strong>UserID:</strong> {item.userId}
                      </p>
                    </div>
                  </div>
                );
              })}
              <div>
                <Link target="self" to="/">
                  Home
                </Link>
              </div>
            </div>
          );
    }
}

export default Details;
// App.js
import React from 'react';
import { Route, Switch } from 'react-router-dom';

import './App.css';

import Home from '../pages/Home';
import Details from '../pages/Details';

function App() {
  return (
    <div className="App">
      <Switch>
        <Route exact path='/' component={Home} />
        <Route exact path='/details/:id' component={Details} />
      </Switch>
    </div>
  );
}

export default App;

导航到 http://localhost:3000/details/1 时的结果

Details Page
Status:

ID: 1

Title: delectus aut autem

UserID: 1

Details Page
Status:

ID: 2

Title: quis ut nam facilis et officia qui

UserID: 1

Details Page
Status:

ID: 3

Title: fugiat veniam minus

UserID: 1

Details Page
Status:

ID: 4

Title: et porro tempora

UserID: 1

Details Page
Status:

ID: 5

Title: laboriosam mollitia et enim quasi adipisci quia provident illum

UserID: 1

Details Page
Status:

ID: 6

Title: qui ullam ratione quibusdam voluptatem quia omnis

UserID: 1

Details Page
Status:

ID: 7

Title: illo expedita consequatur quia in

UserID: 1

Details Page
Status:

ID: 8

Title: quo adipisci enim quam ut ab

UserID: 1

Details Page
Status:

ID: 9

Title: molestiae perspiciatis ipsa

UserID: 1

Details Page
Status:

ID: 10

Title: illo est ratione doloremque quia maiores aut

UserID: 1

Details Page
Status:

ID: 11

Title: vero rerum temporibus dolor

UserID: 1

Details Page
Status:

ID: 12

Title: ipsa repellendus fugit nisi

UserID: 1

Details Page
Status:

ID: 13

Title: et doloremque nulla

UserID: 1

Details Page
Status:

ID: 14

Title: repellendus sunt dolores architecto voluptatum

UserID: 1

Details Page
Status:

ID: 15

Title: ab voluptatum amet voluptas

UserID: 1

Details Page
Status:

ID: 16

Title: accusamus eos facilis sint et aut voluptatem

UserID: 1

Details Page
Status:

ID: 17

Title: quo laboriosam deleniti aut qui

UserID: 1

Details Page
Status:

ID: 18

Title: dolorum est consequatur ea mollitia in culpa

UserID: 1

Details Page
Status:

ID: 19

Title: molestiae ipsa aut voluptatibus pariatur dolor nihil

UserID: 1

Details Page
Status:

ID: 20

Title: ullam nobis libero sapiente ad optio sint

UserID: 1

Details Page
Status:

ID: 21

Title: suscipit repellat esse quibusdam voluptatem incidunt

UserID: 2

Details Page
Status:

ID: 22

Title: distinctio vitae autem nihil ut molestias quo

UserID: 2

Details Page
Status:

ID: 23

Title: et itaque necessitatibus maxime molestiae qui quas velit

UserID: 2

Details Page
Status:

ID: 24

Title: adipisci non ad dicta qui amet quaerat doloribus ea

UserID: 2

Details Page
Status:

ID: 25

Title: voluptas quo tenetur perspiciatis explicabo natus

UserID: 2

Details Page
Status:

ID: 26

Title: aliquam aut quasi

UserID: 2

Details Page
Status:

ID: 27

Title: veritatis pariatur delectus

UserID: 2

Details Page
Status:

ID: 28

Title: nesciunt totam sit blanditiis sit

UserID: 2

Details Page
Status:

ID: 29

Title: laborum aut in quam

UserID: 2

Details Page
Status:

ID: 30

Title: nemo perspiciatis repellat ut dolor libero commodi blanditiis omnis

UserID: 2

Details Page
Status:

ID: 31

Title: repudiandae totam in est sint facere fuga

UserID: 2

Details Page
Status:

ID: 32

Title: earum doloribus ea doloremque quis

UserID: 2

Details Page
Status:

ID: 33

Title: sint sit aut vero

UserID: 2

Details Page
Status:

ID: 34

Title: porro aut necessitatibus eaque distinctio

UserID: 2

Details Page
Status:

ID: 35

Title: repellendus veritatis molestias dicta incidunt

UserID: 2

Details Page
Status:

ID: 36

Title: excepturi deleniti adipisci voluptatem et neque optio illum ad

UserID: 2

Details Page
Status:

ID: 37

Title: sunt cum tempora

UserID: 2

Details Page
Status:

ID: 38

Title: totam quia non

UserID: 2

Details Page

访问 http://localhost:3000/details/1 时的预期结果:

Details Page
Status:

ID: 1

Title: delectus aut autem

UserID: 1
javascript
  • 1 个回答
  • 28 Views
Martin Hope
bdc1
Asked: 2022-08-18 03:32:46 +0000 UTC

使用标签删除重复项

  • 0

我有一个问题:有一个代码(视图),我为它创建了标签,如何使用标签删除重复项?

标签:

from django import template

from recipes.models import Follow, Recipe

register = template.Library()


@register.filter(name='extend_context')
def extend_context(context, user):
    context['purchase_list'] = Recipe.objects.filter(purchase_by=user)
    context['favorites'] = Recipe.objects.filter(favorite_by=user)
    return context


@register.filter(name='add_subscription_status')
def add_subscription_status(context, user, author):
    context['is_subscribed'] = Follow.objects.filter(
        user=user, author=author
    ).exists()
    return context

查看代码:

@require_GET
def recipe_detail(request, recipe_id):
    recipe = get_object_or_404(Recipe, id=recipe_id)
    context = {
        'recipe': recipe,
    }
    user = request.user
    if user.is_authenticated:
        add_subscription_status(context, user, recipe.author) - дублирование
        extend_context(context, user) - дублирование
    return render(request, 'recipes/recipe_detail.html', context)

@require_GET
def profile(request, user_id):
    author = get_object_or_404(User, id=user_id)
    tags = request.GET.getlist('tag')
    recipe_list = tag_filter(Recipe, tags)
    paginator = Paginator(recipe_list.filter(author=author), PAGINATE_BY)
    page_number = request.GET.get('page')
    page = paginator.get_page(page_number)
    context = {
        'tags': Tag.objects.all(),
        'author': author,
        'page': page,
        'paginator': paginator
    }
    user = request.user
    if user.is_authenticated:
        add_subscription_status(context, user, author) - дублирование
        extend_context(context, user) - дублирование
    return render(request, 'recipes/profile.html', context)
python
  • 1 个回答
  • 10 Views
Martin Hope
bdc1
Asked: 2022-06-08 02:01:39 +0000 UTC

macbook air 2019如何连接两台外接显示器?

  • 0

我在 i5 上有一个 macbook air 2019,我从 Baseus 购买了一个适配器(下图),结果是:1 个 hdmi、一个充电连接器和 2 个 usbshni。我通过 hdmi 连接了一台显示器,有什么方法可以连接第二台显示器(可能是 DisplayLink ??)?甚至可能吗?在此处输入图像描述

mac
  • 1 个回答
  • 10 Views
Martin Hope
bdc1
Asked: 2022-06-06 06:12:02 +0000 UTC

堆栈 - 按代码修订,python。需要帮忙!

  • 0

我试图修复导师指出的两个错误(我将在下面描述它们) - 过了一段时间,整个代码停止工作,愚蠢地出现了 3 个回溯。我寻求帮助以修复错误(我认为它们很容易,但我不明白如何将它们倒入代码中)。


错误:

第 29 行: stack.push(int(element))

对于计算器的操作,将“字符串转换为数字”(数字化仪)的特定功能并不重要。因此,最好使其更具通用性。让求解器函数获取“数字化仪”作为默认值为 int 的可选参数。然后计算器将能够使用浮点数/复数/十进制/有理数/...

线 8:9 -

def pop(self):
    self.items.pop()

需要安全码,因为此调用可能会失败


任务: 该任务与逆波兰表示法有关。它用于解析算术表达式。它有时也称为后缀表示法。在后缀表示法中,操作数放在运算符符号之前。示例 1:

3 4 +
означает 3 + 4 и равно 7 

示例 2:

12 5 /
Так как деление целочисленное, то в результате получим 2.
Пример 3: 
10 2 4 * -
означает 10 - 2 * 4 и равно 2 

让我们仔细看看最后一个例子:

* 符号紧跟在数字 2 和 4 之后,这意味着您需要对它们应用此符号表示的操作,即,将这两个数字相乘。结果,我们得到 8。之后,表达式将采用以下形式:

10 8 -

减法运算必须应用于它前面的两个数字,即 10 和 8。结果,我们得到 2。

让我们更详细地考虑该算法。为了实现它,我们将使用堆栈。要计算用逆波兰表示法编写的表达式的值,您需要从左到右读取表达式并执行以下步骤: 处理输入字符:

如果一个操作数作为输入,它被压入栈顶。

如果给输入一个操作符号,那么这个操作就是按照加法的顺序对从栈中取出的所需数量的值进行的。执行操作的结果放在栈顶。

如果输入字符集没有被完全处理,则转到步骤1。输入字符集被完全处理后,表达式求值的结果在栈顶。如果堆栈上剩下几个数字,则只应显示顶部元素。

关于负数和除法的注意事项:在这个问题中,除法是指数学整数除法。这意味着它总是向下取整。即:如果a / b = c,则b ⋅ c 是不超过a 且能同时被b 整除且无余数的最大数。例如,-1 / 3 = -1。请注意:例如,在 C++、Java 和 Go 中,数字除法的工作方式不同。在当前问题中,保证没有除以负数。


输入格式

单行包含一个用反向波兰表示法编写的表达式。数字和算术运算用空格书写。运算可以作为输入:+, -, *, /和数字,模不超过10000。保证测试数据模中的中间表达式的值不超过50000。


输出格式

打印一个数字——表达式的值。


示例 1:

输入:

2 1 + 3 *

结论:

9

示例 2:

输入:

7 2 + 4 * 2 +

结论:

38

我的代码:

class Stack:
    def __init__(self):
        self.items = []

    def push(self, item):
        self.items.append(item)

    def pop(self): - 8:9
        self.items.pop()

    def size(self):
        return len(self.items)


OPERATORS = {'+': lambda x, y: x + y,
             '-': lambda x, y: x - y,
             '*': lambda x, y: x * y,
             '/': lambda x, y: x // y}


def calculator(line, stack=None, operators=OPERATORS):
    stack = Stack() if stack is None else stack
    for element in line:
        if element in operators:
            el1, el2 = stack.pop(), stack.pop()
            stack.push(operators[element](el1, el1))
        else:
            try:
                stack.push(int(element)) - 29 строка
            except:
                raise KeyError('WRONG_KEY')
    return stack.pop()


if __name__ == '__main__':
    line = input().split()
    print(calculator(line))

代码输出错误:

Traceback (most recent call last):
  File "final_b_13.py", line 37, in <module>
    print(calculator(line))
  File "final_b_13.py", line 26, in calculator
    stack.push(operators[element](el1, el1))
  File "final_b_13.py", line 15, in <lambda>
    OPERATORS = {'+': lambda x, y: x + y,
TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'
python
  • 1 个回答
  • 10 Views
Martin Hope
bdc1
Asked: 2022-06-02 20:31:29 +0000 UTC

如何改进代码?堆栈 - python中的任务

  • 0

我有一个代码,我想知道如何加快速度,简化(让它更漂亮:)),让它吃更少的内存,一般来说,有可能做到这一点吗?

目前我有以下结果:时间 - 91 ms | 内存 - 3.98Mb | Python 3.7.3


Gosha 实现了 Dec 数据结构,其最大大小由给定的数字确定。方法push_back(x), push_front(x), pop_back(),pop_front()工作正常。但是,如果套牌中有很多元素,则该程序可以运行很长时间。事实是并非所有操作都在 O(1) 中执行。帮助天哪!编写一个有效的实现。 注意:实现不能使用链表。


输入格式

第一行包含命令数 n — 一个不超过 5000 的整数。第二行包含一个数字m— 最大牌组大小。它不超过 1000。接下来的 n 行包含以下命令之一:

push_back(value)– 在双端队列的末尾添加一个元素。如果双端队列已经包含最大数量的元素,则打印“错误”。

push_front(value)– 在双端队列的开头添加一个元素。如果双端队列已经包含最大数量的元素,则打印“错误”。

pop_front()– 显示双端队列的第一个元素并将其删除。如果双端队列为空,则打印“错误”。

pop_back()– 显示双端队列的最后一个元素并将其删除。如果双端队列为空,则打印“错误”。

Value— 整数,模不超过 1000。输出格式

在单独的行上打印每个命令的结果。对于成功的请求push_back(x),push_front(x)您不需要显示任何内容。


输出格式

在单独的行上打印每个命令的结果。对于成功的请求push_back(x),push_front(x)您不需要显示任何内容。


示例 1:

输入:

4
4
push_front 861
push_front -819
pop_back
pop_back

结论:

861
-819

示例 2:

输入:

7
10
push_front -855
push_front 720
pop_back
pop_back
push_back 844
pop_back
push_back 823

结论:

-855
720
844

示例 3:

输入:

6
6
push_front -201
push_back 959
push_back 102
push_front 20
pop_front
pop_back

结论:

20
102

我的代码:

class Dek:
    def __init__(self, max_size: int):
        self._elements = [None] * max_size
        self._max_size = max_size
        self._head = 0
        self._tail = 0
        self._size = 0

    def is_empty(self):
        return self._size == 0

    def push_back(self, value: int):
        if self._size != self._max_size:
            self._elements[self._tail] = value
            self._tail = (self._tail + 1) % self._max_size
            self._size += 1
        else:
            raise OverflowError

    def push_front(self, value: int):
        if self._size != self._max_size:
            self._elements[self._head - 1] = value
            self._head = (self._head - 1) % self._max_size
            self._size += 1
        else:
            raise OverflowError

    def pop_back(self):
        if self.is_empty():
            raise IndexError
        x = self._elements[self._tail - 1]
        self._elements[self._tail - 1] = None
        self._tail = (self._tail - 1) % self._max_size
        self._size -= 1
        return x

    def pop_front(self):
        if self.is_empty():
            raise IndexError
        x = self._elements[self._head]
        self._elements[self._head] = None
        self._head = (self._head + 1) % self._max_size
        self._size -= 1
        return x


def main():
    count_command = int(input())
    queue_size = int(input())

    queue = Dek(queue_size)
    commands = {
        'push_front': queue.push_front,
        'push_back': queue.push_back,
        'pop_front': queue.pop_front,
        'pop_back': queue.pop_back,
    }
    for i in range(count_command):
        command = input()
        operation, *value = command.split()
        if value:
            try:
                result = commands[operation](int(*value))
                if result is not None:
                    print(result)
            except OverflowError:
                print('error')
        else:
            try:
                result = commands[operation]()
                print(result)
            except IndexError:
                print('error')


if __name__ == '__main__':
    main()
python
  • 1 个回答
  • 10 Views
Martin Hope
bdc1
Asked: 2022-05-26 05:20:05 +0000 UTC

堆栈 - python中的任务

  • 1

我完全不明白如何解决这个问题,我要求对代码进行更多解释。


实现一个类,该类StackMaxEffective支持确定堆栈上元素之间的最大值的操作。操作的复杂度应该是 O(1)。对于空堆栈,操作必须返回None。在这种情况下push(x), 和pop()也必须在恒定时间内执行。

输入格式

第一行包含一个数字——命令的数量,它不超过 100000。然后是命令,每行一个。命令可以是以下类型:

  • push(x)— 将数字 x 添加到堆栈中;
  • pop()- 从栈顶移除一个数字;
  • get_max()- 打印堆栈上的最大数量;

如果堆栈为空,则在调用命令时,需要为命令get_max打印- 。«None»pop«error»

输出格式

对于每个命令get_max(),打印其执行结果。如果堆栈为空,对于命令get_max(),键入«None»。如果从空堆栈中删除,请打印«error»。

示例 1:

输入:

10
pop
pop
push 4
push -5
push 7
pop
pop
get_max
pop
get_max

结论:

error
error
4
None

示例 2:

输入:

10
get_max
push -6
pop
pop
get_max
push 2
get_max
pop
push -2
push -6

结论:

None
error
None
2

Python 3.7.3 | 时间限制 - 1.5 秒 | 内存限制 - 64Mb

我的代码:

class StackMax:
    def __init__(self):
        self.items = []
        self.max_items = []

    def push(self, item):

        if bool(self.items) and bool(self.max_items):
            if item >= self.max_items[-1]:
                self.max_items.append(item)
            return self.items.append(item)
        self.items.append(item)
        self.max_items.append(item)

    def pop(self):
        if bool(self.items) and bool(self.max_items):
            if self.items[-1] == self.max_items[-1]:
                self.max_items.pop()
            return self.items.pop()
        return 'error'

    def get_max(self):
        if bool(self.items) and bool(self.max_items):
            return self.max_items[-1]
        return None
python
  • 1 个回答
  • 10 Views
Martin Hope
bdc1
Asked: 2022-05-23 01:38:29 +0000 UTC

python中的算法任务,如何改进代码?

  • 0

大家好!我最近研究了python中的算法问题,我做了一个问题,我想知道如何改进它?(可能有更多解释)。

Gosha 和 Timofey 找到了一个不寻常的快速打字模拟器,并想掌握它。模拟器是一个 4x4 键的字段,其中每轮出现数字和点的配置。键上写有一个点或从 1 到 9 的数字。在时间 t,玩家必须同时按下写有数字 t 的所有键。Gosha 和 Timofey 可以同时按 k 个键。如果在时间 t 按下了所有必要的键,则玩家获得 1 分。找出如果 Gosha 和 Timofey 一起按键可以赚取的点数。

输入格式

第一行包含一个整数 k (1 ≤ k ≤ 5)。在接下来的四行中,指定了模拟器的类型 - 每行 4 个字符。每个字符可以是一个点,也可以是从 1 到 9 的数字。同一行中的字符是连续的,并且没有空格分隔。

输出格式

打印单个数字,Gosha 和 Timofey 可以获得的最大点数。

示例 1:

输入:

3
1231
2..2
2..2
2..2

结论:

2

示例 2:

输入:

4
1111
9999
1111
9911

结论:

1

示例 3:

输入:

4
1111
1111
1111
1111

结论:

0

时间限制 - 1 秒 | 内存限制 - 64mb

我的版本:

k = int(input()) * 2 #Эти 2 части перенести в if __name__ == "__main__"  и сделать def "snake_case"
matrix = []
for i in range(4):
    numbers = input()
    matrix += numbers
t = 1
score = 0
while t <= 9:
    count_t = matrix.count(str(t))
    if 0 < count_t <= k:
        score += 1 #Тут была идея сделать функцию sum() с условием, чтобы избавиться от лишних строк, но не знаю, нужно это или нет
    t += 1
print(score)
python
  • 3 个回答
  • 10 Views
Martin Hope
bdc1
Asked: 2022-05-20 03:48:42 +0000 UTC

python中的算法任务

  • 0

大家好!最近我开始研究 Python 中的算法问题,遇到了一个我无法以任何方式解决的问题。我请求你的帮助(如果不难,你可以有更多的解释):

Timofey 想要居住的街道长度为 n,也就是说,它由 n 个相同的连续路段组成。要么已经在每个地块上建造了房子,要么地块是空的。Timofey 正在寻找一个地方来建造他的房子。他非常善于交际,不想离住在这条街上的其他人太远。为了最佳地选择施工地点,Timofey 想知道每个地块到最近的空地的距离。(对于空白区域,此值将等于零 - 到自身的距离)。你的任务是帮助蒂莫西计算所需的距离。为此,您有一张街道地图。提摩太城的房屋是按照建造顺序编号的,所以地图上的编号并没有以任何方式排列。空白区域用零标记。

输入格式 第一行包含街道的长度——n (1 ≤ n ≤ 106)。下一行包含 n 个非负整数——房屋数量和地图上空地的名称(零)。保证序列中至少有一个零。门牌号(正数)是唯一的,不超过 109。

输出格式 对于每个段,输出到最接近零的距离。在一行上输出数字,用空格分隔。

示例 1:

输入:

5

0 1 4 9 0

结论:

0 1 2 1 0

示例 2:

输入:

6

0 7 9 4 8 20

结论:

0 1 2 3 4 5

蟒蛇 | 时间限制:3 秒 | 内存限制:256 MB

根据我的猜测,我们需要找到左边最近的地段的距离,然后对于右边最近的地段,下一步:最近的空房子要么是最近的左边,要么是最近的右边。

编码:

n = int(input())
numbers = input().split()
for i in range(n):
    if numbers[i] != '0':
        l = 10**6
        for a in range(n):
            if numbers[i - a] == '0':
                if a <= i and l > a:
                    l = a
                if a > i and l > n - a:
                    l = n - a
            numbers[i] = l
print(*numbers)
python
  • 2 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5