对于html–直接在其他单词之下或之上放置单词感兴趣的读者,本文将提供您所需要的所有信息,我们将详细讲解html底部单词,并且为您提供关于1455.检查单词是否为句中其他单词的前缀:简单模拟题、c语言
对于html – 直接在其他单词之下或之上放置单词感兴趣的读者,本文将提供您所需要的所有信息,我们将详细讲解html底部单词,并且为您提供关于1455. 检查单词是否为句中其他单词的前缀 : 简单模拟题、c 语言:输入一行字符,统计其中的单词个数,单词之间用空格分开、HTML – 单词中的单词、html – 在背景图像上放置左边距的宝贵知识。
本文目录一览:- html – 直接在其他单词之下或之上放置单词(html底部单词)
- 1455. 检查单词是否为句中其他单词的前缀 : 简单模拟题
- c 语言:输入一行字符,统计其中的单词个数,单词之间用空格分开
- HTML – 单词中的单词
- html – 在背景图像上放置左边距
html – 直接在其他单词之下或之上放置单词(html底部单词)
使用跨度,单词将以不同方式着色.
我将在文本框中给出一些文本,并通过JavaScript我需要动态更新到div以显示类似上面的内容.
做这个的最好方式是什么?
它会涉及等宽字体吗?
它会涉及写“隐藏”文本吗?
我希望以这种方式完成整个段落.
这可能看起来很奇怪,但我正在进行的研究要求我提供具有多种颜色的给定文本中的某些单词,我认为这可能是传达此信息的一种很好的方式.
更新文本框中的文本将更新以下变量,反过来我需要将这两个变量转换为类似上图的内容.
text = "I am under the text above me and there is lots more text to come./n I am even moving onto a new line since I have more text" color_per_word_position = {0:green,1: red,2: cyan,4: yellow,5: red,...}
解决方法
我基本上看到两个选项:1.使用空格2.边距.
选项1
你的文字看起来像
I•am•under•the•text•above ••am•under•••••text•above
其中•表示空格字符.在CSS方面非常简单,因为您不必担心间距.浏览器为您完成所有操作.示例:http://jsfiddle.net/PYXdr/
*好吧,有可能使用任何字体,使用大量的JS,但我想这不值得.
选项2
由于您可能不希望在跨度之间使用空格,因此您可能更喜欢这样:
I•am•under•the•text•above am•under text•above
现在,需要手动处理间距.每个跨度应该得到一个左边距,将其推到所需的位置.但在我们能够做到这一点之前,我们需要知道一个字符的宽度(使用JS,因为CSS没有提供).好的,非常简单:
var el = document.createElement('pre'); el.style.display = 'inline-block'; el.innerHTML = ' '; document.body.appendChild(el); var width = parseFloat(getComputedStyle(el).width); document.body.removeChild(el);
现在让我们继续前进并移动跨度:
span1.style.marginLeft = (2 * width) + 'px'; span2.style.marginLeft = (5 * width) + 'px';
示例:http://jsfiddle.net/JC3Sc/
把它们放在一起
现在,这是一个如何工作的基本示例:
var text = "I am under the text above me and there is lots more text to come.\nI am even moving onto a new line since I have more text" var highlightBorders = [[2,3,4,6],[6,7]]; // YOUR TASK: implement the logic to display the following lines var color_per_word_position = {0:'lime',1: 'red',2: 'cyan',3:'orange',4: 'yellow',5: 'red'} /* generate CSS */ var style = document.createElement('style'); for (var i in color_per_word_position) { style.innerHTML += '.hl' + i + '{background:' + color_per_word_position[i] + '}'; } document.head.appendChild(style); /* generating the text */ text = text.split('\n'); var pre = document.createElement('pre'); text.forEach(function (line,i) { var div = document.createElement('div'); var words = line.split(' '); var result = []; highlightBorders[i].forEach(function (len,j) { var span = document.createElement('span'); span.innerHTML = words.splice(0,len).join(' '); span.className = 'hl' + j; if (j) { span.style.marginLeft = width + 'px' // YOUR TASK: implement the logic } div.appendChild(span); }); pre.appendChild(div); }); document.body.appendChild(pre);
这不是一个完整的解决方案,因为a)我真的没有看到你要突出的部分和b)我不想破坏所有的乐趣.但是你明白了.
示例:http://jsfiddle.net/tNyqL/
1455. 检查单词是否为句中其他单词的前缀 : 简单模拟题
题目描述
这是 LeetCode 上的 1455. 检查单词是否为句中其他单词的前缀 ,难度为 简单。
Tag : 「模拟」、「双指针」
给你一个字符串 sentence
作为句子并指定检索词为 searchWord
,其中句子由若干用 单个空格 分隔的单词组成。请你检查检索词 searchWord
是否为句子 sentence
中任意单词的前缀。
如果 searchWord
是某一个单词的前缀,则返回句子 sentence
中该单词所对应的下标(下标从 $1$ 开始)。如果 searchWord
是多个单词的前缀,则返回匹配的第一个单词的下标(最小下标)。如果 searchWord
不是任何单词的前缀,则返回 $-1$ 。
字符串 s
的前缀是 s
的任何前导连续子字符串。
示例 1:
输入:sentence = "i love eating burger", searchWord = "burg"
输出:4
解释:"burg" 是 "burger" 的前缀,而 "burger" 是句子中第 4 个单词。
示例 2:
输入:sentence = "this problem is an easy problem", searchWord = "pro"
输出:2
解释:"pro" 是 "problem" 的前缀,而 "problem" 是句子中第 2 个也是第 6 个单词,但是应该返回最小下标 2 。
示例 3:
输入:sentence = "i am tired", searchWord = "you"
输出:-1
解释:"you" 不是句子中任何单词的前缀。
提示:
- $1 <= sentence.length <= 100$
- $1 <= searchWord.length <= 10$
sentence
由小写英文字母和空格组成。searchWord
由小写英文字母组成。
模拟
根据题意进行模拟即可。
Java 代码:
class Solution {
public int isPrefixOfWord(String s, String t) {
String[] ss = s.split(" ");
int n = ss.length, m = t.length();
for (int i = 0; i < n; i++) {
if (ss[i].length() < m) continue;
boolean ok = true;
for (int j = 0; j < m && ok; j++) {
if (ss[i].charAt(j) != t.charAt(j)) ok = false;
}
if (ok) return i + 1;
}
return -1;
}
}
Typescript 代码:
function isPrefixOfWord(s: string, t: string): number {
const ss = s.split(" ")
const n = ss.length, m = t.length
for (let i = 0; i < n; i++) {
if (ss[i].length < m) continue
let ok = true
for (let j = 0; j < m && ok; j++) {
if (ss[i][j] != t[j]) ok = false
}
if (ok) return i + 1
}
return -1
};
- 时间复杂度:$O(n \times m)$
- 空间复杂度:$O(n)$
最后
这是我们「刷穿 LeetCode」系列文章的第 No.1455
篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先把所有不带锁的题目刷完。
在这个系列文章里面,除了讲解解题思路以外,还会尽可能给出最为简洁的代码。如果涉及通解还会相应的代码模板。
为了方便各位同学能够电脑上进行调试和提交代码,我建立了相关的仓库:https://github.com/SharingSou... 。
在仓库地址里,你可以看到系列文章的题解链接、系列文章的相应代码、LeetCode 原题链接和其他优选题解。
更多更全更热门的「笔试/面试」相关资料可访问排版精美的 合集新基地
本文由mdnice多平台发布
c 语言:输入一行字符,统计其中的单词个数,单词之间用空格分开
#include<stdio.h>
int main()
{
int = 0, word = 0, i = 0;
char str[40];
gets(str);
while(str[i] != ''\0'')
{
if(str[i] == '' '')
{
word = 0;
}
else
{
if(0 == word)
{
++;
word = 1;
}
else
{
word = 1;
}
}
i++;
}
printf("%d\n",);
return 0;
}
HTML – 单词中的单词
<div> <div> <div>this_is_a_really_long_text_without_spaces</div> <divhttps://www.jb51.cc/tag/Now/" target="_blank">Nowrap">:-)</div> </div> </div> <div> <div> <div>this is a really long text without spaces</div> <divhttps://www.jb51.cc/tag/Now/" target="_blank">Nowrap">:-)</div> </div> </div>
这个css
.externalWidth { width: 200px; } .container { margin-bottom:10px; display:inline-table; height:40px; width:100%; } .element { display:table-cell; } .Nowrap { white-space:Nowrap; }
我做了一个jsfiddle来演示它.两个.elements中的文本都是从服务器读取并通过knockout绑定.我希望它看起来如下:
>第二个元素应该有足够的空间
>第一个.elements应该有剩余的空间.如果可能的话,它应该分成多行.
一切都很好但长话会导致整个表格扩展.如果有必要,是否有可能在言语中打破?
我也尝试了表格布局:固定;但这就产生了两个100px的柱子.
编辑:谢谢.分手:打破一切;完全按照我的需要做了.
解决方法
试试这个DEMO
html – 在背景图像上放置左边距
我的意图是我想留下200px的背景图像.我的代码如下所示,或者您可以查看此jsfiddle: http://jsfiddle.net/benmore/D5sNs/
<style type="text/css"> body{ margin-left:200px; background:#5d9ab2 url(https://lh5.googleusercontent.com/-ZBLYo1oD6bM/UHox3oBICxI/AAAAAAAAAgo/yCg6TcxLeC4/s358/img_tree.png) no-repeat top left; } .container { text-align:center; width: 100px; } </style> <title></title> </head> <body> <div> test </div> </body>
我唯一的问题是背景是左边靠近.
我该怎么做才能让它从页面的左边缘开始200px?
解决方法
演示:http://jsfiddle.net/D5sNs/1/
background-position CSS属性允许您在容器周围放置背景图像.在这里阅读更多:http://reference.sitepoint.com/css/background-position
关于html – 直接在其他单词之下或之上放置单词和html底部单词的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于1455. 检查单词是否为句中其他单词的前缀 : 简单模拟题、c 语言:输入一行字符,统计其中的单词个数,单词之间用空格分开、HTML – 单词中的单词、html – 在背景图像上放置左边距的相关知识,请在本站寻找。
本文标签: