[BOJ] 2011 암호코드

Time Lapse :NONE

2011.cpp

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
#include <iostream>
#include <memory.h>
#include <string>

using namespace std;


int main(void)
{
string str;
int dp[5001];
cin>>str;
if(str.at(0)=='0') {
cout << "0" << endl;
return 0;
}
memset(dp,0,sizeof(dp));
dp[0]=1;
dp[1]=1;
for(int i=2;i<=str.length();i++)
{
if(str.at(i-1)!='0')
dp[i]=dp[i-1];
int x = (str.at(i-2)-48)*10+str.at(i-1)-48;
if(10<=x&&x<=26)
dp[i]=(dp[i]+dp[i-2])%1000000;
}
cout<<dp[str.length()]<<endl;

}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/BOJ/2011/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.