結果

問題 No.18 うーさー暗号
コンテスト
ユーザー megane_anko
提出日時 2021-03-15 02:48:26
言語 TypeScript
(6.0.2)
コンパイル:
tsc.sh -p tsconfig.json
実行:
node main.js ONLINE_JUDGE
結果
AC  
実行時間 117 ms / 5,000 ms
コード長 870 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,805 ms
コンパイル使用メモリ 349,236 KB
実行使用メモリ 53,228 KB
最終ジャッジ日時 2026-06-05 05:32:55
合計ジャッジ時間 7,109 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import * as fs from 'fs';
const input = fs.readFileSync('/dev/stdin', 'utf8');

const nlarray = input.split('\n');
const Sarray = nlarray[0].split('');
const ABC = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const ABCarray = ABC.split('');
let result = [];

//それをSarray全体やってもらうのにまわすfor 文は
for (let i = 0;i < Sarray.length; i++) {
    //ABCのどこに一致するか調べてインデックスを返してもらって、(i + 1)引く
    let result_index = (ABCarray.indexOf(Sarray[i]) - (i + 1)) % 26;
    //ABC配列の中でanswer番目のものを取得する
    //result_indexがマイナスの値になると文字を取ってこれないので、1周分多く足す
    if (result_index < 0) {
        result_index  = result_index + 26;
    }
    let answer = ABCarray[result_index];
    result.push(answer);
}
console.log(result.join(''));
0