結果

問題 No.18 うーさー暗号
コンテスト
ユーザー Kuphony
提出日時 2016-03-16 21:07:55
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 762 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 474 ms
コンパイル使用メモリ 77,240 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-03-28 21:05:39
合計ジャッジ時間 896 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'std::string convertString(std::string, int)':
main.cpp:15:16: warning: 'currentNum' may be used uninitialized [-Wmaybe-uninitialized]
   15 |     currentNum -= n;
      |     ~~~~~~~~~~~^~~~
main.cpp:7:9: note: 'currentNum' was declared here
    7 |     int currentNum;
      |         ^~~~~~~~~~

ソースコード

diff #
raw source code

#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