RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

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

全部问题

Martin Hope
Follin
Asked: 2024-10-28 15:29:19 +0000 UTC

将一列中的值拆分为 2 列

  • 6

我有以下 Excel 文件:

在此输入图像描述

在 Python 中,它看起来像这样:

在此输入图像描述

如何转换数据,以便名称列中的数字形成另一列?

或者使用正则表达式进行排序,以便对于每个名称都满足第 8、9 和 10 个月内有访问的条件?

python
  • 1 个回答
  • 39 Views
Martin Hope
gw gw
Asked: 2024-10-28 08:21:31 +0000 UTC

为什么要使用模运算来计算循环队列的尾部?

  • 5

我发现了这个实现循环队列的例子,但我不太明白 的含义 if((self.tail + 1) % self.size == self.head),如果你可以使用队列大小:(self.tail == self.size - 1)或者也可以在增加变量的(self.tail < self.size)情况下更改它。也许有一些关于数组溢出的主题,我只是不太明白如何进行调试,因为我使用ide并且不明白如何以常规方式进行调试。elsetailAtomcmd

import random

class MyCircularQueue():
    def __init__(self, size):
        self.size = size
        self.queue = [None] * size
        self.head = self.tail = -1

    def enqueue(self, data):
        if((self.tail + 1) % self.size == self.head):
            print("The queue is full\n")
        elif (self.head) == -1:
            self.head = 0
            self.tail = 0
            self.queue[self.tail] = data
        else:
            self.tail = (self.tail +1) % self.size
            self.queue[self.tail] = data

    def dequeue(self):
        if(self.head == -1):
            print("The queue is empty\n")
        elif(self.head == self.tail):
            temp = self.queue[self.head]
            self.head = -1
            self.tail = -1
            return temp
        else:
            temp = self.queue[self.head]
            self.head = (self.head + 1) % self.size
            return temp

    def printqueue(self):
        if(self.head == -1):
            print("Is empty, i cant print\n")

        elif(self.tail >= self.head):
            for i in range(self.head, self.tail + 1):
                print(self.queue[i], end = " ")
            print()
        else:
            for i in range(self.head, self.size):
                print(self.queue[i], end = " ")
            for i in range(0, self.tail + 1):
                print(self.queue[i], end = " ")
            print()

que = MyCircularQueue(5)
for x in range(que.size):
    que.enqueue(random.randint(1, 10))

que.printqueue()

UPD:我将条件更改为self.tail == self.size - 1,并将增量设置为self.tail。显示队列后,发现没有添加新元素,并显示队列已满的消息。我决定更改输出,不显示元素本身,而是显示其在队列中的索引。事实证明,删除是从左到右进行的,添加是从右侧进行的。

Before Delete: 0 1 2 3 4 After Delete: 1 2 3 4 After additional number: 1 2 3 4 0

事实证明,如果您设置增量,则它tail不会重置,并且始终具有适合新条件的最后一个值。

UPD2:在本文中找到了方法实现的示例isEmpty()

python
  • 1 个回答
  • 24 Views
Martin Hope
Sirop4ik
Asked: 2024-10-28 05:05:54 +0000 UTC

当我制作动画时,底部栏导航给出白色背景

  • 5

我正在尝试在底部导航上制作一个简单的动画

这是代码:

@Composable
private fun BottomNavImpl() {
    Scaffold(
        bottomBar = {
            var isBottomBarVisible: Boolean by remember { mutableStateOf(false) }

            LaunchedEffect(Unit) {
                delay(2000)
                isBottomBarVisible = true
            }

            AnimatedVisibility(
                visible = isBottomBarVisible,
                enter = slideInVertically(
                    initialOffsetY = { it },
                    animationSpec = tween(
                        durationMillis = 500,
                        easing = FastOutSlowInEasing
                    )
                ),
                exit = slideOutVertically(
                    targetOffsetY = { it },
                    animationSpec = tween(
                        durationMillis = 300,
                        easing = FastOutSlowInEasing
                    )
                )
            ) {
                NavigationBar(
                    containerColor = Color.Red,
                ) {
                    repeat(3) {
                        NavigationBarItem(
                            icon = {
                                Icon(
                                    modifier = Modifier,
                                    painter = painterResource(android.R.drawable.ic_menu_add),
                                    contentDescription = null,
                                )
                            },
                            selected = false,
                            onClick = { }
                        )
                    }
                }
            }
        },
        content = { paddingValues ->
            Box(
                modifier = Modifier
                    .fillMaxSize()
                    .padding(paddingValues)
                    .background(Color.Green)
            ) {

            }
        }
    )
}

这是结果

在此输入图像描述

问题是在动画过程中,后面出现白色背景

android
  • 1 个回答
  • 17 Views
Martin Hope
Sirop4ik
Asked: 2024-10-28 04:37:23 +0000 UTC

如何使 LazyGrid 上某个项目的动画仅在第一次发生?

  • 5

这应该不会太困难,但由于某种原因,重组经历了两次,这使得添加仅第一次执行动画的条件变得困难。

一般来说,我想像这个例子那样做,但我改变了一点,但本质是一样的 - https://yasincamaz.medium.com/simple-item-animation-with-jetpack-composes-lazygrid -78316992af22

网格元素出现气泡效果是必要的

这是代码

private val dataSet: List<String> = listOf("Item 1", "Item 2", "Item 3", "Item 4", "Item 5")
private val data: List<String> = List(5) { dataSet }.flatten()

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContent {
            Test_delete_itTheme {
                Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
                    Gallery(
                        paddingValues = innerPadding,
                        uiConfig = { data }
                    )
                }
            }
        }
    }
}

@Composable
private fun Gallery(
    paddingValues: PaddingValues,
    uiConfig: () -> List<String>
) {
    val config: List<String> = uiConfig()
    val columns = 2

    Column(
        modifier = Modifier
            .fillMaxSize()
            .padding(paddingValues)
    ) {
        LazyVerticalGrid(
            columns = GridCells.Fixed(columns),
            modifier = Modifier.fillMaxSize(),
            verticalArrangement = Arrangement.spacedBy(8.dp),
            horizontalArrangement = Arrangement.spacedBy(8.dp),
            content = {
                items(config.size) { idx ->
                    val item: String = config[idx]
                    val (scale, alpha) = scaleAndAlpha(idx, columns)

                    MyItem(
                        modifier = Modifier.graphicsLayer(alpha = alpha, scaleX = scale, scaleY = scale),
                        text = item
                    )
                }
            }
        )
    }
}

@Composable
private fun MyItem(
    modifier: Modifier = Modifier,
    text: String
) {
    Card(
        modifier = modifier.height(150.dp),
        shape = RoundedCornerShape(16.dp),
        elevation = CardDefaults.cardElevation(8.dp),
        colors = CardDefaults.cardColors(
            containerColor = Color.Blue,
        )
    ) {
        Box(
            modifier = Modifier
                .weight(1f)
                .height(150.dp)
                .clip(RoundedCornerShape(16.dp))
        ) {
            Text(
                text = text,
                color = Color.White
            )
        }
    }
}

@Immutable
private enum class State { PLACING, PLACED }

@Immutable
data class ScaleAndAlphaArgs(
    val fromScale: Float,
    val toScale: Float,
    val fromAlpha: Float,
    val toAlpha: Float
)

@OptIn(ExperimentalTransitionApi::class)
@Composable
fun scaleAndAlpha(
    args: ScaleAndAlphaArgs,
    animation: FiniteAnimationSpec<Float>
): Pair<Float, Float> {
    val transitionState = remember { MutableTransitionState(State.PLACING).apply { targetState = State.PLACED } }
    val transition = rememberTransition(transitionState, label = "")
    val alpha by transition.animateFloat(transitionSpec = { animation }, label = "") {
        if (it == State.PLACING) args.fromAlpha else args.toAlpha
    }
    val scale by transition.animateFloat(transitionSpec = { animation }, label = "") {
        if (it == State.PLACING) args.fromScale else args.toScale
    }
    return alpha to scale
}

val scaleAndAlpha: @Composable (idx: Int, columns: Int) -> Pair<Float, Float> = { idx, columns ->
    scaleAndAlpha(
        args = ScaleAndAlphaArgs(2f, 1f, 0f, 1f),
        animation = tween(300, delayMillis = (idx / columns) * 100)
    )
}

您可以尝试将Gallery其更改为此以跟踪该元素是否已向用户显示

@Composable
private fun Gallery(
    paddingValues: PaddingValues,
    uiConfig: () -> List<String>
) {
    val config: List<String> = uiConfig()
    val columns = 2

    // Remember a set of already animated indices
    val animatedIndices = remember { mutableSetOf<Int>() }

    Column(
        modifier = Modifier
            .fillMaxSize()
            .padding(paddingValues)
    ) {
        LazyVerticalGrid(
            columns = GridCells.Fixed(columns),
            modifier = Modifier.fillMaxSize(),
            verticalArrangement = Arrangement.spacedBy(8.dp),
            horizontalArrangement = Arrangement.spacedBy(8.dp),
            content = {
                items(config.size) { idx ->
                    val item: String = config[idx]

                    // Determine if the item should animate
                    val shouldAnimate = !animatedIndices.contains(idx)

                    // If it should animate, mark it as animated
                    if (shouldAnimate) {
                        animatedIndices.add(idx)
                    }

                    val (scale, alpha) = if (shouldAnimate) {
                        scaleAndAlpha(idx, columns)
                    } else {
                        1f to 1f // No animation
                    }

                    MyItem(
                        modifier = Modifier.graphicsLayer(alpha = alpha, scaleX = scale, scaleY = scale),
                        text = item
                    )
                }
            }
        )
    }
}

但问题是,这里每个元素都会调用两次重组 -items(config.size) { idx ->因此,该元素出现在屏幕上就好像没有动画一样

我在这里缺少什么?

android
  • 1 个回答
  • 23 Views
Martin Hope
Vit
Asked: 2024-10-28 02:44:08 +0000 UTC

PHP7.4:使用命名空间时,执行时无法识别函数名(但编写代码时一切正常)。人工智能搞砸了他们的头,我也是。

  • 4

我决定训练自己解决各种面试问题的能力,并且全面地对待一切:composer、PHPUnit...

看起来一切都做得正确,无论是结构还是嵌套。但是当我运行测试时,消息是:调用未定义的函数。

同时:在IDE中编写代码时,用函数代替它们,参数的描述取自PHPDoc结构。当通过 required 连接时 - 一切正常,但这是“错误的”。

现在我们来具体说明一下。

“项目”结构

PHPInterviewTasks/
├── src/
│   ├── phpZoneTasks/
│   │   └── LargestPossibleNumberFromOthers.php
├── tests/
│   ├── phpZoneTasksTests/
│   │   └── LargestPossibleNumberFromOthersTest.php
├── vendor/
├── composer.json
└── phpunit.xml

LargestPossibleNumberFromOthers.php:

<?php
namespace PHPInterviewTasks\phpZoneTasks;

function getLargeNumberFromOthers (string $line): string
{
$tmp_array = explode(" ", $line);

usort($tmp_array, function($p1, $p2) {
    $order1 = $p1 . $p2;
    $order2 = $p2 . $p1;
    return $order2 <=> $order1;
});
return implode('', $tmp_array);
}

包含测试 LargestPossibleNumberFromOthersTest.php 的文件:

<?php
use PHPUnit\Framework\TestCase;
//use function InterviewTasks\phpZoneTasks\getLargeNumberFromOthers;
use function \PHPInterviewTasks\phpZoneTasks\getLargeNumberFromOthers;
use  \PHPInterviewTasks\phpZoneTasks;
//require_once __DIR__ . '/../../src/phpZoneTasks/LargestPossibleNumberFromOthers.php';

class LargestPossibleNumberFromOthersTest extends TestCase {
    public function testGetLargeNumberFromOthers()
    {
       $this->assertEquals("9958142211100", getLargeNumberFromOthersAlias("100 95 9 2 42 11 81"));
    }
}

PS 注释的使用选项显示了一些实验。

好吧,composer.json

{
  "name": "php-projects/interview-tasks",
  "description": "Examples, Solutions for interview",
  "minimum-stability": "stable",
  "license": "proprietary",
  "authors": [
    {
      "name": "vitaly_root",
      "email": "[email protected]"
    }
  ],
  "require": {
    "php": ">=7.4"
  },
  "require-dev": {
    "phpunit/phpunit": "^9.5"
  },
  "autoload": {
    "psr-4": {
      "PHPInterviewTasks\\": "src/"
    }
  },
  "autoload-dev": {
    "psr-4": {
      "PHPInterviewTasks\\Tests\\": "tests/"
    }
  },
  "scripts": {
    "test": "phpunit"
  }
}

2 人工智能系统已经在愚蠢地原地踏步了。我将很感激能有一个工作版本能够将这种耻辱转化为正确的形式。

php
  • 1 个回答
  • 29 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