結果
| 問題 | No.18 うーさー暗号 |
| コンテスト | |
| ユーザー |
Kuphony
|
| 提出日時 | 2016-03-16 21:07:55 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 762 bytes |
| コンパイル時間 | 643 ms |
| コンパイル使用メモリ | 62,356 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-07 06:01:23 |
| 合計ジャッジ時間 | 1,261 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 13 |
コンパイルメッセージ
main.cpp: In function ‘std::string convertString(std::string, int)’:
main.cpp:15:16: warning: ‘currentNum’ may be used uninitialized in this function [-Wmaybe-uninitialized]
15 | currentNum -= n;
| ~~~~~~~~~~~^~~~
ソースコード
#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";
}
Kuphony