結果
問題 | No.18 うーさー暗号 |
ユーザー | Elk |
提出日時 | 2018-05-26 02:45:56 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1 ms / 5,000 ms |
コード長 | 722 bytes |
コンパイル時間 | 159 ms |
コンパイル使用メモリ | 23,552 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-28 18:07:57 |
合計ジャッジ時間 | 805 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 13 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:20:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 20 | scanf("%s", str); | ~~~~~^~~~~~~~~~~ main.cpp: In function ‘int abc_num(char)’: main.cpp:13:12: warning: ‘ret’ may be used uninitialized in this function [-Wmaybe-uninitialized] 13 | return ret; | ^~~ main.cpp: In function ‘int main()’: main.cpp:26:16: warning: ‘ret’ may be used uninitialized in this function [-Wmaybe-uninitialized] 26 | if(pos - (i%26 + 1) >= 0){ | ~~~~^~~~~~~~~~~~
ソースコード
#include <stdio.h> #include <string.h> char abc[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int abc_num(char a){ int i, ret; for(i = 0; i < 26; i++){ if(a == abc[i]){ ret = i; } } return ret; } int main(){ char str[1025]; int len, i, pos, str_pos; scanf("%s", str); len = strlen(str); //printf("len = %d\n", len); for(i = 0; i < len; i++){ pos = abc_num(str[i]); if(pos - (i%26 + 1) >= 0){ str_pos = pos - (i%26 + 1); }else{ str_pos = pos - (i%26 + 1) + 26; } //printf("%d\n", str_pos); str[i] = abc[str_pos]; } //printf("len2 = %ld\n", strlen(str)); printf("%s\n", str); }