当前位置:网站首页>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));
});
边栏推荐
- 克隆无向图[bfs访问每条边而不止节点]
- Divisor
- The role of VMware virtual machine
- Gradle serialization 7- configuration signature
- vlog常用参数解析
- Fine grained identification, classification, retrieval data set collation
- JS绘制极坐标颜色渐变
- 500 error occurred after importing skins folder into solo blog skin
- 8软件工程环境
- FPGA Development (2) -- IIC communication
猜你喜欢

Koa2 learning and using

Et la tarte aux framboises 4? Quels sont les jeux possibles?

Siemens low code version 9.14: meet different needs
![克隆無向圖[bfs訪問每條邊而不止節點]](/img/34/2a1b737b6095293f868ec6aec0ceeb.png)
克隆無向圖[bfs訪問每條邊而不止節點]

Halcon practical: design idea of solder joint detection

QT learning 02 GUI program example analysis

AI首席架构师9-胡晓光 《飞桨模型库与行业应用》

JS draw polar color gradient

JS的初步语法

Color space conversion in video tonemapping (HDR to SDR) (bt2020 to bt709, YCbCr, YUV and RGB)
随机推荐
Construction of module 5 of actual combat Battalion
如何实现搜索引擎中的拼写纠错功能——思路
History of deep learning
333333333333333333333333333333
云原生爱好者周刊:炫酷的 Grafana 监控面板集合
Cacti settings for spin polling
[rust weekly library] Tokei - a utility for statistics of code lines and other information
8软件工程环境
Halcon practical: design idea of solder joint detection
New CorelDRAW technical suite2022 latest detailed function introduction
Solr基础操作10
koa2学习和使用
Buffer flow exercise
solo 博客皮肤导入 skins 文件夹后出现 500 错误
Koa2 learning and using
请指教同花顺软件究竟是什么?究竟网上开户是否安全么?
Vulnhub target -moriartycorp
【微信小程序】认识小程序项目的基本组成结构
After 8 years of polishing, "dream factory of game design" released an epic update!
Machine learning: the concept and application of VC dimension