Algorithm

[BOJ] 2011번 : 암호코드

rudgh99_algo 2024. 9. 5. 17:47

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