結果
問題 | No.18 うーさー暗号 |
ユーザー |
![]() |
提出日時 | 2021-03-15 02:48:26 |
言語 | TypeScript (5.7.2) |
結果 |
AC
|
実行時間 | 64 ms / 5,000 ms |
コード長 | 870 bytes |
コンパイル時間 | 8,382 ms |
コンパイル使用メモリ | 228,696 KB |
実行使用メモリ | 39,552 KB |
最終ジャッジ日時 | 2024-12-31 16:34:14 |
合計ジャッジ時間 | 9,868 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 13 |
ソースコード
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(''));