当前位置:网站首页>Preliminary syntax of JS
Preliminary syntax of JS
2022-06-30 00:11:00 【Shanlan ~】

Two common ways to introduce code ;


If js Written in head in , This is equivalent to a global variable ,
ctrl tab Switch files ;
token It's a token , You take the token interface to admit .
let buf = "";
process.stdin.on("readable", function(){
let chunk = process.stdin.read();
if(chunk) buf+= chunk.toString()
;})
process.stdin.on("end", function(){
// let [x,y] = buf.split(' ').map(x => {return parseInt(x)});
let [x,y] = buf.split(' ').map(function(x){
return parseInt(x)});
let price = [4.00,4.50,5.00,2.00,1.50];
let res = y * price[x - 1];
console.log(`Total: R$ ${
res.toFixed(2)}`);
})
Notice which line of the comment , Both can run , It is equivalent. ;
if else sentence
let buf = "";
process.stdin.on("readable", function(){
let chunk = process.stdin.read();
if (chunk) buf += chunk.toString();
})
process.stdin.on("end", function(){
// let a = buf.split('').map(x => {return x});
// The above method is wrong ;
let a = parseFloat(buf);
if(a >= 0 && a <= 25){
console.log("Intervalo [0,25]");
}
else if (a>25 && a <= 50)
{
console.log("Intervalo (25,50]");
}
else if( a > 50 && a <= 75)
{
console.log("Intervalo (50,75]");
}
else if (a > 75 && a <= 100)
{
console.log("Intervalo (75,100]");
}
else
{
console.log("Fora de intervalo");
}
})
let buf = "";
process.stdin.on("readable", function() {
let chunk = process.stdin.read();
if (chunk) buf += chunk.toString();
});
process.stdin.on("end", function() {
let [a, b, c] = buf.split('\n');
if (a === "vertebrado") {
if (b === "ave") {
if (c === "carnivoro") {
console.log("aguia");
} else {
console.log("pomba");
}
} else {
if (c === "onivoro") {
console.log("homem");
} else {
console.log("vaca");
}
}
} else {
if (b === "inseto") {
if (c === "hematofago") {
console.log("pulga");
} else {
console.log("lagarta");
}
} else {
if (c === "hematofago") {
console.log("sanguessuga");
} else {
console.log("minhoca");
}
}
}
});
The upper part , Be careful split() Part of the is based on ’\n’; It's not a space ;
- loop
eg721 Increasing sequence :
let x;// Remember to initialize
let buf = '';
process.stdin.on("readable", function(){
let chunk = process.stdin.read();
if (chunk) buf += chunk.toString();
});
process.stdin.on("end", function(){
let xs = buf.split('\n').map(function(x){
return parseInt(x);
});
for (let x of xs){
if (x === 0) break;
let line = "";
for (let i = 1; i <= x; i ++)
line += `${
i} `; // because console.log() Carriage return present So we splice the string first and then enter
console.log(line);
}
});
because console.log() Carriage return present So we splice the string first and then enter
let n = parseInt(buf);
// let m = n/2;
let m = parseInt(n / 2);
Be careful m It's different here , Must pass
let m = parseInt(n / 2);
such , Not directly equal to n/2;
- Array

process.stdin.on("end", function(){
let lines = buf.split('\n');
let n = parseInt(lines[0]);
let op = lines[1];
let d = [];
for(let i = 0 ; i < 12 ; i ++)
{
d.push(lines[i+2].split(' ').map(x => {
return parseFloat(x)}))
}
let sum = 0;
for(let i = 0 ; i <12 ; i ++ )
sum+=d[n][i];
if(op==='M') sum/=12;
console.log(`${
sum.toFixed(1)}`);
})
Appreciate the idea of segmentation ;
- function
let buf = "";
process.stdin.on("readable", function() {
let chunk = process.stdin.read();
if (chunk) buf += chunk.toString();
});
let max = (x, y) => {
return x > y ? x : y;
};
process.stdin.on("end", function() {
let [x, y] = buf.split(' ').map(x => {
return parseInt(x)});
console.log(max(x, y));
});
边栏推荐
- Cacti maximum monitoring number test
- EB-5 immigration in the United States reappears to be positive, and the reauthorization policy of the regional center is suspended
- 代码分析平台 SonarQube 实战
- JVM之栈空间
- 西门子低代码平台通过Database Connector 连接Mysql 实现增删改查
- Majority element ii[molar voting method for finding modes]
- Mysql:sql overview and database system introduction | dark horse programmer
- Unity splashimage scaling problem
- 一步步教你在Edge浏览器上安装网风笔记
- Will the flush SQL CDC parallelism affect the order? Generally, only 1 can be set for data synchronization.
猜你喜欢

Fine grained identification, classification, retrieval data set collation

Color space conversion in video tonemapping (HDR to SDR) (bt2020 to bt709, YCbCr, YUV and RGB)

Introduction to reptiles: data capture of Betta barrage, with 11 introductory notes attached

Buffer flow exercise

koa2学习和使用

數莓派 4怎麼樣?可能的玩法有哪些?

MySQL:SQL概述及数据库系统介绍 | 黑马程序员

FPGA Development (1) -- serial port communication

333333333333333333333333333333

Leetcode (680) -- verifying palindrome string II
随机推荐
數莓派 4怎麼樣?可能的玩法有哪些?
爬虫入门实战:斗鱼弹幕数据抓取,附送11节入门笔记
Andorid source build/envsetup. SH details to know
西门子低代码 9.14版本: 满足不同需求
gyctf_2020_document
JS绘制极坐标颜色渐变
Buffer flow exercise
如何实现搜索引擎中的拼写纠错功能——思路
This PMP Exam (June 25), some people are happy and others are worried. That's why
Solr基础操作13
How to view the CPU cores and threads in win11? Win11 view the tutorial of how many cores and threads the CPU is
Solr basic operation 11
ThinkPad VMware installation virtual machine: this host supports Intel VT-x, but Intel VT-x is disabled (problem resolution)
克隆无向图[bfs访问每条边而不止节点]
Basic tutorial for installing monggodb in win10
Some specifications based on zfoo development project
手机开户后多久才能通过?另外,手机开户安全么?
koa2学习和使用
QT learning 07 coordinate system in QT
Solr basic operations 9