알고리즘/BAEKJOON
백준 1718번 암호
pureworld
2018. 11. 6. 21:46
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 | #include <iostream> #include <string> #include<cstring> using namespace std; int main() { char a[30] = "abcdefghijklmnopqrstuvwxyz"; string s; string s2; getline(cin, s); //로직 자체는 어려울 것이 없다. 입력방식에 공백을 넣을수 있는 getline(cin, s2); //방법에 두가지가 있음에 유의하자 /* char s2[30000]; char s[30000]; cin.getline(s, 30001, '\n'); //널문자 때문에 +1 cin.getline(s2, 30001, '\n');*/ for (int i = 0; s[i]!='\0'; i++) { if (s[i] == ' ') { cout << " "; continue; } int p = i%s2.length(); int j= s[i]-s2[p]; if (j == 0) { cout << "z"; } else if (j > 0) { cout << a[j - 1]; } else if (j < 0&&j>-26) { cout << a[26 + j - 1]; } } return 0; } | cs |
문제 출처:https://www.acmicpc.net/problem/1718
문제 피드백,질문은 댓글로 부탁드려요~!