22/08/18 学习
代码地址
ACgit仓库地址
提交版本:react(4)Redux:组件store相互通信
版本号:fca6f4ea09ae7cc72f3130125fb8caba461541cb
代码仓库:https://git.acwing.com/AndyLaw/KOF
let buf = ''
process.stdin.on('readable',function(){
var chunk = process.stdin.read();
if (chunk) buf += chunk.toString();
});
let path = [], st = [];
function dfs(k, n) {
if (k === n) console.log(path.join(' '));
else {
for (let i = 1; i <= n; i ++ ) {
if (!st[i]) {
path.push(i);
st[i] = true;
dfs(k + 1, n);
path.pop();
st[i] = false;
}
}
}
};
process.stdin.on("end", function() {
let n = parseInt(buf);
dfs(0, n);
});
let buf = "";
process.stdin.on("readable", function() {
let chunk = process.stdin.read();
if (chunk) buf += chunk.toString();
});
function sort(a, l, r) {
if (l >= r) return ;
let i = l - 1, j = r + 1, mid = a[l + r >> 1];
while (i < j) {
do {i ++ } while (a[i] < mid);
do {j -- } while (a[j] > mid);
if (i < j) [a[i], a[j]] = [a[j], a[i]];
}
sort(a, l, j);
sort(a, j + 1, r);
}
process.stdin.on("end", function() {
let lines = buf.split('\n');
let [n, l, r] = lines[0].split(' ').map(x => {return parseInt(x)});
let seq = lines[1].split(' ').map(x => {return parseInt(x)});
sort(seq, l, r);
// .join(' ') 把数组seq所有元素变成一个字符串,用' '隔开
console.log(seq.join(' '));
});
let buf = "";
process.stdin.on("readable", function() {
let chunk = process.stdin.read();
if (chunk) buf += chunk.toString();
});
function gcd(a, b) {
let res = 0;
for (let i = 1; i <= Math.max(a, b); i ++ ) {
if ((a % i) === 0 && (b % i) === 0)
res = Math.max(res, i);
}
// console.log(res);
return res;
}
process.stdin.on("end", function() {
let [a, b] = buf.split(' ').map(x => {return parseInt(x)});
// gcd(a, b);
console.log(gcd(a, b));
});
let buf = "";
process.stdin.on("readable", function() {
let chunk = process.stdin.read();
if (chunk) buf += chunk.toString();
});
function print2D(matrix, row, col) {
for (let i = 0; i < row; i ++ )
console.log(matrix[i].join(' '));
}
process.stdin.on("end", function() {
let lines = buf.split('\n');
let [a, b] = lines[0].split(' ').map(x => {return parseInt(x)});
let res = [];
for (let i = 0; i < a; i ++ ) {
res.push(lines[i + 1].split(' ').map(x => {return parseInt(x)}));
}
print2D(res, a, b);
});
let buf = "";
process.stdin.on("readable", function() {
let chunk = process.stdin.read();
if (chunk) buf += chunk.toString();
});
function max(a, b) {
if (a > b) return a;
else return b;
}
process.stdin.on("end", function() {
let [a, b] = buf.split(' ').map(x => {return parseInt(x)});
console.log(max(a, b));
});