当前位置:网站首页>JS的初步语法
JS的初步语法
2022-06-30 00:00:00 【山岚~】

两种常见代码的引入方式;


如果js写在head中, 相当于是全局变量,
ctrl tab切换文件;
token就是令牌,你带着令牌接口才会承认。
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)}`);
})
注意看注释的哪一行, 二者都可以运行, 是等价的;
if else语句
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});
//上面的这种方法是错误的;
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");
}
}
}
});
上面的部分, 注意split()中的部分是根据’\n’;不是空格;
- 循环
eg721递增序列:
let x;//记得有需要初始化
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} `; //因为console.log()存在回车 故我们先拼接字符串然后再回车
console.log(line);
}
});
因为console.log()存在回车 故我们先拼接字符串然后再回车
let n = parseInt(buf);
// let m = n/2;
let m = parseInt(n / 2);
注意m这里是不一样的,必须通过
let m = parseInt(n / 2);
这种, 而不能直接等于n/2;
- 数组

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)}`);
})
好好体会分块的思想吧;
- 函数
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));
});
边栏推荐
- Construction of module 5 of actual combat Battalion
- Siemens low code platform connects MySQL through database connector to realize addition, deletion, modification and query
- Solr basic operation 16
- Golang泛型的巧妙应用,防止变量空指针错误,防止结构体字段空指针错误
- Zhongang Mining: Fluorite helps the construction and development of lithium battery in fluorine industry
- Viewing splitchunks code segmentation from MPX resource construction optimization
- Activity invitation | the Apache Doris community essay and speech solicitation activity has begun!
- Construction of module 5 of actual combat Battalion
- 由GlideException: Failed DecodePath{DirectByteBuffer->GifDrawable->Drawable}引起的刨根问底
- Solr基础操作7
猜你喜欢

New titanium cloud service won the "2022 love analysis · panoramic report of it operation and maintenance manufacturers" cloud management platform CMP representative manufacturer

Halcon practical: design idea of solder joint detection

Binary search tree 230 The element with the smallest K in the binary search tree 1038 From binary search tree to larger sum tree

Leetcode (76) -- Minimum Covering substring

QT learning 01 GUI program principle analysis

New CorelDRAW technical suite2022 latest detailed function introduction

西门子低代码 9.14版本: 满足不同需求

Golang6 reflection

This PMP Exam (June 25), some people are happy and others are worried. That's why

6.29日刷题题解
随机推荐
Leetcode (633) -- sum of squares
I wonder if I can open an account today? In addition, is it safe to open an account online now?
New CorelDRAW technical suite2022 latest detailed function introduction
如何实现搜索引擎中的拼写纠错功能——思路
JVM之栈空间
Viewing splitchunks code segmentation from MPX resource construction optimization
Binary search tree 230 The element with the smallest K in the binary search tree 1038 From binary search tree to larger sum tree
Divisor
Solr基础操作7
Solr basic operation 10
西门子低代码平台通过Database Connector 连接Mysql 实现增删改查
Construction of module 5 of actual combat Battalion
MySQL functions and constraints
Zhongkang holdings opens the offering: it plans to raise HK $395million net, and it is expected to be listed on July 12
Cacti settings for spin polling
koa2学习和使用
Sword finger offer 14- ii Cutting rope II
Summary of DOM knowledge points
爬虫入门实战:斗鱼弹幕数据抓取,附送11节入门笔记
Digital collection of cultural relics, opening a new way of cultural inheritance