Submission #26182583


Source Code Expand

#include <iostream>

std::string caesar_cipher(std::string &s, int n) {
  char table[0xff] = {0};

  for (int t = 0; t < 0xff; t++) {
    table[t] = t;
  }

  for (int i = 0; i < 26; i++) {
    char upper_ch_src = 'A' + i;
    char upper_ch_dst = 'A' + (i + n) % 26;
    char lower_ch_src = 'a' + i;
    char lower_ch_dst = 'a' + (i + n) % 26;

    table[(int)upper_ch_src] = upper_ch_dst;
    table[(int)lower_ch_src] = lower_ch_dst;
  }

  std::string res = "";
  for (int i = 0; i < (int)s.size(); i++) {
    char ch = s[i];
    res += table[(int)ch];
  }

  return res;
}

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);

  std::string cipher_text;

  std::cin >> cipher_text;
  std::cout << caesar_cipher(cipher_text, 26 - 3) << "\n";

  return 0;
}

Submission Info

Submission Time
Task C - シーザー暗号
User kira924age
Language C++ (GCC 9.2.1)
Score 100
Code Size 817 Byte
Status AC
Exec Time 6 ms
Memory 3628 KiB

Judge Result

Set Name set01 set02 set03 set04 set05
Score / Max Score 20 / 20 20 / 20 20 / 20 20 / 20 20 / 20
Status
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
Set Name Test Cases
set01 data1
set02 data2
set03 data3
set04 data4
set05 data5
Case Name Status Exec Time Memory
data1 AC 6 ms 3588 KiB
data2 AC 2 ms 3628 KiB
data3 AC 2 ms 3460 KiB
data4 AC 2 ms 3496 KiB
data5 AC 2 ms 3536 KiB