当前位置:网站首页>在牛客中使用JS编程题【split】
在牛客中使用JS编程题【split】
2022-06-28 02:16:00 【qq_22841387】
问题描述
今天做题的时候发现句子逆序
这个题目特别适合使用js做,于是记录一次JS做题
其实开始的时候,我不太知道这个如何JS读写,然后搜了一下直接读取即可
解决代码
var str = readline();
let arr = str.split(" ");
let ans = "";
for(let i = arr.length - 1 ; i >= 0 ; i --){
ans = ans + arr[i] + " ";
}
console.log(ans);
值得注意的几个点
JS输入问题
首先就是JS输入问题。
因为在牛客里面,所以的一切都是需要自己从0到1 直接写的,但是JS好像也没有c++和C那样的输入和东西,开始以为就直接就是一个函数
没想到最后就是readline就可以解决问题了,不愧是弱类型语言,脚本语言啊
处理逻辑
因为单词是通过空格分开的,所以直接使用JS中String的分割函数split即可split(" ")
split函数的官方说明
The split() method divides a String into an ordered list of substrings, puts these substrings into an array, and returns the array. The division is done by searching for a pattern; where the pattern is provided as the first parameter in the method’s call.
大致意思
这个split方法分割一个字符串编程一个有序的子串序列,将这些子串放入一个数组,并返回一个数组。
这个分割可以通过正侧分割,正则在方法的回调函数中作为第一个参数
边栏推荐
- [today in history] June 23: Turing's birthday; The birth of the founder of the Internet; Reddit goes online
- 【522. 最长特殊序列 II】
- 2022安全员-C证考试题库模拟考试平台操作
- 嵌入式DSP音频开发
- Artifact for converting pcap to JSON file: joy (installation)
- s32ds跳转到DefaultISR
- RichView TRVStyle TextStyles
- 目标检测|SSD原理与实现
- Reading makes people quiet
- 华为设备WLAN基本业务配置命令
猜你喜欢

业内首个!可运行在移动设备端的视频画质主观体验MOS分评估模型!

分布式事务解决方案Seata-Golang浅析

s32ds跳转到DefaultISR

collections.defaultdict()的使用

How to judge that the thread pool has completed all tasks?
![[plug in -statistical] statistics the number of code lines and related data](/img/84/ad5e78f7e0ed86d9c21cabe97b9c8e.png)
[plug in -statistical] statistics the number of code lines and related data

音视频技术开发周刊 | 251
![[today in history] June 24: Netease was established; The first consumer electronics exhibition was held; The first webcast in the world](/img/f7/b3239802d19d00f760bb3174649a89.jpg)
[today in history] June 24: Netease was established; The first consumer electronics exhibition was held; The first webcast in the world
![[today in history] June 19: iPhone 3GS launched; Pascal was born; Anti terrorist elite begins testing](/img/ec/90961351a0de1eac26dd003bf25d34.png)
[today in history] June 19: iPhone 3GS launched; Pascal was born; Anti terrorist elite begins testing

【活动早知道】LiveVideoStack近期活动一览
随机推荐
云成本优化有哪些优秀实践?
[today in history] June 24: Netease was established; The first consumer electronics exhibition was held; The first webcast in the world
视频编解码性能优化与实现
be fond of the new and tired of the old? Why do it companies prefer to spend 20K on recruiting rather than raise salaries to retain old employees
Apache——阿帕奇简介
Initial linear regression
R语言惩罚逻辑回归、线性判别分析LDA、广义加性模型GAM、多元自适应回归样条MARS、KNN、二次判别分析QDA、决策树、随机森林、支持向量机SVM分类优质劣质葡萄酒十折交叉验证和ROC可视化
Severe Tire Damage:世界上第一个在互联网上直播的摇滚乐队
业内首个!可运行在移动设备端的视频画质主观体验MOS分评估模型!
Mysql database operation - stored procedure, view, transaction, index, database backup
R1 Quick Open Pressure Vessel Operation Special Operation Certificate Examination Library and Answers in 2022
拾光者,云南白药!
Tips for visiting the website: you are not authorized to view the recovery method of this page
RichView TRVStyle
Artifact for converting pcap to JSON file: joy (installation)
Inference optimization implementation of tensorrt model
How to write concise code? (upper)
论文阅读:Generative Adversarial Transformers
How fiddle uses agents
CI & CD 不可不知!