結果

問題 No.163 cAPSlOCK
ユーザー intercept6
提出日時 2020-08-06 14:55:30
言語 TypeScript
(5.7.2)
結果
AC  
実行時間 63 ms / 5,000 ms
コード長 791 bytes
コンパイル時間 7,727 ms
コンパイル使用メモリ 229,028 KB
実行使用メモリ 39,552 KB
最終ジャッジ日時 2024-12-31 16:16:54
合計ジャッジ時間 10,106 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

import { readFileSync } from 'fs';

const codeA = 'A'.charCodeAt(0);
const codeZ = 'Z'.charCodeAt(0);

function isUpperCase(character: string): boolean {
  // if (character.length !== 1) {
  //   throw new Error(`${character}は1文字ではありません。`);
  // }
  const characterCode = character.charCodeAt(0);
  return codeA <= characterCode && characterCode <= codeZ;
}

function Main(input: string) {
  const data = input.split('\n');

  const passowrd = data[0];

  for (let i = 0; i < passowrd.length; i++) {
    const character = passowrd.charAt(i);
    if (isUpperCase(character)) {
      process.stdout.write(character.toLowerCase());
    } else {
      process.stdout.write(character.toUpperCase());
    }
  }
  console.log('');
}

Main(readFileSync('/dev/stdin', 'utf8'));
0