3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

これのやつです。

今回は、「どんな風に書いていこうかな」ってノリを模索するために書いてます。
書き方は他の人のを真似しています。

問題

解答コード

process.stdin.resume();
process.stdin.setEncoding('utf8');
// 自分の得意な言語で
// Let's チャレンジ!!
var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line);
});
reader.on('close', () => {
    const winningNumber = Number(lines[0]);
    
    const adjacents = [];
    if(100000 < winningNumber) adjacents.push(String(winningNumber - 1));
    if(199999 > winningNumber) adjacents.push(String(winningNumber + 1));
    
    const n = Number(lines[1]);
    for(let i=0; i<n; i++){
        const currentNumber = lines[i+2];
        
        if(currentNumber === lines[0]){
            console.log("first");
        }else if(adjacents.includes(currentNumber)){
            console.log("adjacent");
        }else if(currentNumber.endsWith(lines[0].substr(-4))){
            console.log("second");
        }else if(currentNumber.endsWith(lines[0].substr(-3))){
            console.log("third");
        }else{
            console.log("blank");
        }
    }
    
});

解説

色つけと書き込みすぎて汚いかも
CleanShot 2024-07-20 at 20.46.45@2x.png

感想

自分なりに解説書いてみたけど見にくいかも。
というか問題文のスクショって載せて大丈夫なのだろうか。
とりあえず、その時々でこんな感じでやってみる。

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?