[BOJ] 2011번 : 암호코드

2024. 9. 5. 17:47Algorithm

1. problem : 

https://www.acmicpc.net/problem/2011

 

 

2. solution 1 :

#include <bits/stdc++.h>
using namespace std;
int d[5005]; 
int nums[5005];
const int mod = 1000000;
int main(void) {
	ios::sync_with_stdio(0);
	cin.tie(0); 
	string s;
	cin >> s; 
	for (int i = 1; i <= s.length(); i++) {
		nums[i] = s[i-1] - '0'; 
	} 
	d[0] = 1; 
	for (int i = 1; i <= s.length(); i++) {
		if (nums[i] > 0) d[i] = (d[i] + d[i - 1]) % mod; 
		int x = nums[i - 1] * 10 + nums[i]; 
		if (x >= 10 && x <= 26) d[i] = (d[i] + d[i - 2]) % mod;
	}
	cout << d[s.length()];

}

source code 출처 : https://github.com/encrypted-def/basic-algo-lecture/blob/master/0x10/solutions/2011.cpp

 

basic-algo-lecture/0x10/solutions/2011.cpp at master · encrypted-def/basic-algo-lecture

바킹독의 실전 알고리즘 강의 자료. Contribute to encrypted-def/basic-algo-lecture development by creating an account on GitHub.

github.com

 

'Algorithm' 카테고리의 다른 글

[BOJ] 1931번 : 회의실 배정  (0) 2024.09.06
[BOJ] 11047번 : 동전 0  (3) 2024.09.06
[BOJ] 9655번 : 돌 게임  (0) 2024.09.05
[BOJ] 10942번 : 팰린드롬?  (0) 2024.09.05
[BOJ] 1915번 : 가장 큰 정사각형  (0) 2024.09.04