Try
[Programmers/C++] 피보나치 시저 암호 본문
출처
코딩 도장
http://codingdojang.com/scode/626?answer_mode=hide
문제- 피보나치 시저 암호를 만드시오
맨 처음 줄에는 정수인 암호키가 주어진다. (0 < N < 10000 )
그 다음 줄에는 변환하고 싶은 문자열이 주어진다.
문자열의 길이만큼 피보나치 수로 바꿔 문자열을 바꾸시오.
(예를 들어 암호키가 4 라면 수열은 1,4,5,9 . . . 로 되어 그 숫자만큼 문자열을 돌린다.)
입력에 소문자는 들어가 있지않으며 기호나 숫자가 들어가 있을 시 그대로 둔다. ( 공백 포함)
(시작은 무조건 1이다.)
입력)
1
AAAAA
1
HELLO, WORLD!
3
ABCDE
출력)
BBCDF
IFNOT, EMBTG!
BEGKP
소스
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | /* /* /* khsh5592@naver.com /* has3ong.tistory.com /* /* 2018 - 11 - 12 /* */ #include<stdio.h> #include<iostream> #include<conio.h> #define MAX_SIZE 100 using namespace std; char C[] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"}; char cal_Index(char Input_str, int step) { for(int i = 0; i< 26; i++) { if(Input_str == C[i]) { step = (i+step) % 26; Input_str = C[step]; return Input_str; } } } void FIBONACCI(int count, int Input_int, char* Input_str) { int first = 1; int second = Input_int; int tmp = 0; //첫 번째 문자 Input_str[0] = cal_Index(Input_str[0], first); //두 번째 문자 Input_str[1] = cal_Index(Input_str[1], second); for(int i = 2; i<count; i++) { if(Input_str[i] >= 65 && Input_str[i] <= 90) { tmp = first+second; first = second; second = tmp; Input_str[i] = cal_Index(Input_str[i], second); } else { Input_str[i] = Input_str[i]; } } for(int i = 0; i < count; i++) { cout << Input_str[i]; } } void main() { int count = 0; int Input_Fibo; char Input_String[MAX_SIZE]; cin.getline(Input_String, MAX_SIZE, '\n'); cin >> Input_Fibo; for(int i = 0; i < MAX_SIZE; i++) { if(Input_String[i] == '\0') { count = i; break; } } FIBONACCI(count,Input_Fibo, Input_String); getch(); } | cs |
결과화면
'Algorithm > Programmers' 카테고리의 다른 글
[Programmers/C++] 카펫 (0) | 2018.11.12 |
---|---|
[Programmers/C++] 최빈값 구하기 (0) | 2018.11.12 |
[Programmers/C++] 타겟 넘버 (0) | 2018.11.12 |
[Programmers/C++] Ugly Number 구하기 (0) | 2018.11.12 |
[Programmers/C++] 배열의 중복된 값 찾기. (0) | 2018.11.11 |
Comments