알고리즘 문제/BOJ
1718번 암호
parkit
2019. 1. 4. 16:06
728x90
반응형
https://www.acmicpc.net/problem/1718
구현 문제다.
a 97
b 98
.
.
.
z 122
나열하고, 예제를 보면서, 숫자를 써가면서 풀었다.
살짝 복잡하긴 했으나, 논리가 어렵지 않고, 문제에도 친절히 설명이 나와있다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | #include <iostream> #include <queue> #include <stack> #include <cstdio> #include <vector> #include <cstring> #include <string> #include <math.h> #include <algorithm> #include <map> using namespace std; int main(void) { string e, s; getline(cin, e); // 평문 getline(cin, s); // 암호화 키 int p = 0, a = 0; while(p < e.length()) // 평문 { if (a == s.length()) a = 0; if (e.at(p) == ' ') { printf(" "); ++p; ++a; continue; } int First = (int)e.at(p); // 평문 int Second = (int)s.at(a); // 암호화키 int diff = abs(First - Second); int move = Second - 'a' + 1; if (First - move < 97) printf("%c", char('z' - diff)); else printf("%c", char(First - move)); ++p; ++a; } printf("\n"); return 0; } | cs |
728x90
반응형