AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-22509381

vilnius19's questions

Martin Hope
vilnius19
Asked: 2023-12-06 00:28:42 +0800 CST

为什么在 Python 中颠倒句子后,最终字符串的单词之间没有空格?[复制]

  • 6
这个问题在这里已经有了答案:
反转句子中的单词 pythonic (3 个答案)
10 小时前关闭。

所以,我正在解决一个 Leetcode 问题,给定一个字符串,我必须反转其中的所有单词并返回反转的短语。以下是问题陈述

给定一个输入字符串 s,反转单词的顺序。

单词被定义为非空格字符的序列。s 中的单词将至少由一个空格分隔。

返回由单个空格按相反顺序连接的单词字符串。

请注意,s 可能在两个单词之间包含前导或尾随空格或多个空格。返回的字符串应该只有一个空格来分隔单词。请勿包含任何额外空格。**

例子 :

输入:s =“天空是蓝色的”

输出:“蓝色是天空”

但我得到的输出如下blueisskythe。我确实尝试在 .join() 之前添加空格,但我没有得到我想要的输出。下面是我的代码

这是我写的代码:

class Solution(object):
    def reverseWords(self,str1):
        ss = str1.split(' ')
        final_str = ""
        for i in range(len(ss)-1,-1,-1):
            final_str += "".join(ss[i])
        return final_str
    
if __name__ == '__main__':
    str = "the sky is blue"
    print(Solution().reverseWords(str))
python
  • 1 个回答
  • 58 Views
Martin Hope
vilnius19
Asked: 2023-09-25 12:23:14 +0800 CST

为什么在 Python 的每日温度问题中我的输出部分不正确?

  • 4

我正在尝试使用两个指针来解决以下问题 给定一个整数数组温度代表每日温度,返回一个数组答案,使得答案[i]是在第i天之后您必须等待以获得更温暖的温度的天数。如果未来没有一天可以这样做,则保留answer[i] == 0。

以下是我的代码:

class Solution(object):

    def dailyTemperatures(self, temperatures):

        l = 0
        r = 1
        res = []
        

        while r < len(temperatures):

            if temperatures[r] > temperatures[l]:
                diff = temperatures[r] - temperatures[l]
                res.append(diff)
                l += 1
                r += 1
               
            else:
                diff = temperatures[l] - temperatures[r]
                res.append(diff)
                l += 1
                r += 1
                

        return res

因此对于以下输入;温度 = [73,74,75,71,69,72,76,73] ,它应该显示输出:[1,1,4,2,1,1,0,0] 但对于我的代码,它显示输出= [1,1,4,2,3,4,3]。 我的方法哪里出了问题?

python
  • 1 个回答
  • 26 Views
Martin Hope
vilnius19
Asked: 2023-09-17 21:40:46 +0800 CST

如何使recyclerviews在android中从右到左和从左到右水平滚动?

  • 5

我在一个片段中有 3 个 recyclerview,我希望每个 recyclerview 都位于另一个之下,然后当我滚动时,它们应该从左到左滚动。他们都不应该干扰其他回收者的观点。以下是我的片段的 xml 布局文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="120dp"
        android:background="@drawable/flash_tablebar"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        android:layout_alignParentTop="true">

        <ImageView
            android:id="@+id/back_icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:src="@drawable/ic_arrow_back" />

        <RelativeLayout
            android:layout_marginLeft="20dp"
            android:id="@+id/relativeFlashcard"
            android:layout_width="wrap_content"
            android:layout_height="100dp"
            android:layout_toRightOf="@id/back_icon">
            <TextView
                android:id="@+id/title_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textStyle="bold"
                android:layout_marginStart="30dp"
                android:text="Flashcards"
                android:textSize="40sp"
                android:textColor="#FFF" />
            <TextView
                android:id="@+id/subtext_flash"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textStyle="bold"
                android:layout_below="@id/title_text"
                android:layout_marginStart="30dp"
                android:text="Pick a set to practice"
                android:textSize="20sp"
                android:textColor="#FFF" />
        </RelativeLayout>
    </androidx.appcompat.widget.Toolbar>

    <LinearLayout
        android:layout_below="@id/toolbar"
        android:layout_width="match_parent"
        android:id="@+id/linear1"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="10dp">
        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recyclerViewFlashcardsEasy"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="10dp"
            android:layout_marginEnd="10dp"
            android:layout_marginTop="10dp"
            android:layout_below="@id/toolbar"
            android:layout_alignParentBottom="true"
            android:scrollbars="horizontal">
        </androidx.recyclerview.widget.RecyclerView>
    </LinearLayout>


    <LinearLayout
        android:layout_below="@id/linear1"
        android:id="@+id/linear2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="10dp">
        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recyclerViewFlashcardsMedium"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="10dp"
            android:layout_marginEnd="10dp"
            android:layout_marginTop="10dp"
            android:layout_below="@id/toolbar"
            android:layout_alignParentBottom="true"
            android:scrollbars="horizontal">
        </androidx.recyclerview.widget.RecyclerView>
    </LinearLayout>


    <LinearLayout
        android:id="@+id/linear3"
        android:layout_below="@id/linear2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="10dp">
        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recyclerViewFlashcardsHard"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="10dp"
            android:layout_marginEnd="10dp"
            android:layout_marginTop="10dp"
            android:layout_below="@id/toolbar"
            android:layout_alignParentBottom="true"
            android:scrollbars="horizontal">
        </androidx.recyclerview.widget.RecyclerView>
    </LinearLayout>
</RelativeLayout>

item_flashcards.xml是Recylerviews中声明元素的布局文件

<androidx.core.widget.NestedScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <androidx.cardview.widget.CardView
            android:layout_width="270dp"
            android:layout_height="150dp"
            android:layout_margin="10dp"
            android:layout_gravity="center"
            android:id="@+id/cardFlashCards"
            app:cardCornerRadius="25dp"
            app:cardElevation="4dp"
            >
            <LinearLayout
                android:layout_width="300dp"
                android:layout_height="200dp"
                android:gravity="center"
                android:layout_gravity="center"
                android:background="@drawable/flashcard_color"
                android:orientation="vertical">

                <ImageView
                    android:id="@+id/imageViewFlashcards"
                    android:layout_width="90dp"
                    android:layout_height="90dp"
                    android:layout_marginTop="20dp"
                    android:layout_gravity="center"
                    android:scaleType="fitXY"
                    android:background="@drawable/circular_flashcardview" />

                <TextView
                    android:id="@+id/textflashCardName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Text1"
                    android:textColor="@color/white"
                    android:layout_marginTop="10dp"
                    android:gravity="center"
                    android:textStyle="bold"
                    android:textSize="18sp" />
                <TextView
                    android:id="@+id/textflashCardLithuanian"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Text2"
                    android:textColor="@color/white"
                    android:layout_marginBottom="10dp"
                    android:gravity="center"
                    android:textStyle="bold"
                    android:textSize="18sp" />
            </LinearLayout>
        </androidx.cardview.widget.CardView>
    </FrameLayout>

</androidx.core.widget.NestedScrollView>

以下是片段的代码

import android.annotation.SuppressLint
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.cardview.widget.CardView
import androidx.navigation.Navigation
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.visuallithuanian.R
import com.example.visuallithuanian.adapter.FlashcardsAdapter
import com.example.visuallithuanian.data.FlashCardInfo
import com.example.visuallithuanian.ui.activities.FirstScreen
import com.google.android.material.bottomnavigation.BottomNavigationView
import dagger.hilt.android.AndroidEntryPoint


@AndroidEntryPoint
class FlashCards : Fragment() {

    lateinit var bottomNav:BottomNavigationView

    @SuppressLint("MissingInflatedId")
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {

        // Inflate the layout for this fragment
        val view=inflater.inflate(R.layout.fragment_flash_cards, container, false)

        //Taking the bOTTOMNavigation view instance from Activity into Fragment
        bottomNav = (activity as? FirstScreen)?.findViewById(R.id.bottomNavigationView)!!
        bottomNav.visibility = View.VISIBLE

        val back_icon = view.findViewById<ImageView>(R.id.back_icon)
        val recyclerViewCardsEasy = view.findViewById<RecyclerView>(R.id.recyclerViewFlashcardsEasy)
        val recyclerViewCardsMedium = view.findViewById<RecyclerView>(R.id.recyclerViewFlashcardsMedium)
        val recyclerViewCardsHard = view.findViewById<RecyclerView>(R.id.recyclerViewFlashcardsHard)


        recyclerViewCardsHard.layoutManager = LinearLayoutManager(context)
        recyclerViewCardsMedium.layoutManager = LinearLayoutManager(context)
        recyclerViewCardsEasy.layoutManager = LinearLayoutManager(context)

        val navController = Navigation.findNavController(requireActivity(),
            R.id.nav_host_fragment
        )

        val flashCardList = generateFlashCards()
        val adapter = FlashcardsAdapter(flashCardList,navController)
        recyclerViewCardsHard.adapter = adapter

        val easyFlashCardsList = generateEasyFlashCards()
        val adapter1 = FlashcardsAdapter(easyFlashCardsList,navController)
        recyclerViewCardsEasy.adapter = adapter1

        val mediumFlashCardsList = generateMediumFlashCards()
        val adapter2 = FlashcardsAdapter(mediumFlashCardsList,navController)
        recyclerViewCardsMedium.adapter = adapter2



        // setting up listener
        back_icon.setOnClickListener {
            activity?.onBackPressed()
        }

        return view
    }

    private fun generateMediumFlashCards(): List<FlashCardInfo> {
        return listOf(
            FlashCardInfo(R.drawable.clothing,"Clothing",""),
            FlashCardInfo(R.drawable.village,"Towns and Villages",""),
            FlashCardInfo(R.drawable.nature,"Nature",""),

        )

    }

    private fun generateEasyFlashCards(): List<FlashCardInfo> {

        return listOf(
            FlashCardInfo(R.drawable.talking,"Daily Conversation",""),
            FlashCardInfo(R.drawable.food,"Food",""),
            FlashCardInfo(R.drawable.relatives,"Relatives",""),
        )

    }

    private fun generateFlashCards():List<FlashCardInfo> {
        return listOf(

            FlashCardInfo(R.drawable.doctorvisit,"Questions and Pronouns",""),
            FlashCardInfo(R.drawable.verbs,"Popular Verbs",""),
        )

    }


}

以下是适配器类的代码

package com.example.visuallithuanian.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.cardview.widget.CardView
import androidx.navigation.NavController
import androidx.navigation.findNavController
import androidx.recyclerview.widget.RecyclerView
import com.example.visuallithuanian.data.FlashCardInfo
import com.example.visuallithuanian.ui.activities.fragments.FlashCardsDirections


class FlashcardsAdapter(private val imageList: List<FlashCardInfo>
,  private val navController: NavController
) :RecyclerView.Adapter<FlashcardsAdapter.ViewHolder>(){

    inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val imageViewFlashcards = itemView.findViewById<ImageView>(com.example.visuallithuanian.R.id.imageViewFlashcards)
        val textViewFlashcards = itemView.findViewById<TextView>(com.example.visuallithuanian.R.id.textflashCardName)
        val textViewFlashcardsLithuanian = itemView.findViewById<TextView>(com.example.visuallithuanian.R.id.textflashCardLithuanian)

        val cardviewFlashcard = itemView.findViewById<CardView>(com.example.visuallithuanian.R.id.cardFlashCards)

    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(com.example.visuallithuanian.R.layout.item_flashcards, parent, false)
        return ViewHolder(view)

    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val current_item = imageList[position]

        holder.imageViewFlashcards.setImageResource(current_item.imageId)
        holder.textViewFlashcards.text = current_item.name
        holder.textViewFlashcardsLithuanian.text = current_item.translation
        
        holder.cardviewFlashcard.setOnClickListener {
            val action = when(position){
                    1 ->FlashCardsDirections.actionFlashCardsToQuestionsFragment()

                else -> return@setOnClickListener
            }
            action.let {
                navController.navigate(it)
            }

        }


    }


    override fun getItemCount(): Int {
        return imageList.size
    }
}

我哪里错了?我什至使那些父线性布局方向水平

android
  • 1 个回答
  • 22 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

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

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve