結果

問題 No.18 うーさー暗号
ユーザー KuphonyKuphony
提出日時 2016-03-16 21:07:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 762 bytes
コンパイル時間 488 ms
コンパイル使用メモリ 63,496 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-21 12:09:08
合計ジャッジ時間 1,274 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,500 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘std::__cxx11::string convertString(std::__cxx11::string, int)’:
main.cpp:15:16: warning: ‘currentNum’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     currentNum -= n;
     ~~~~~~~~~~~^~~~

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

string convertString(string a,int n){
    int currentNum;
    string list[26] = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
    for (int i = 0; i < 26; i++) {
        if(list[i] == a){
            currentNum = i;
            break;
        }
    }
    currentNum -= n;
    while(currentNum < 0){
        currentNum += 26;
    }
    return list[currentNum%26];
}

int main(int argc, const char * argv[]) {
    string s;
    cin >> s;
    string result;
    string tmp;
    for (int i = 0; i < s.length(); i++) {
        tmp = s[i];
        result += convertString(tmp,i+1);
    }
    cout << result;
    cout << "\n";
}
0