목록Algorithm (154)
cgy12306
// https://www.acmicpc.net/problem/2579 // 계단 오르기 #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, stair[301], dp[301]; cin >> n; for (int i = 0; i > stair[i]; } dp[0] = stair[0]; dp[1] = max(stair[0] + stair[1], stair[1]); dp[2] = max(stair[0] + stair[2], stair[1] + stair[2]); for (int i = 3; i < n; i++) { dp..

알고리즘을 풀던 도중 의문을 갖게 하는 코드가 하나 나왔습니다. 어떤 것이냐면 바로 string 출력에 관한 코드였습니다. #include #include #include using namespace std; int main() { string s = "abcde"; string s2 = "abc\0de"; s[2] = 0; cout
// https://www.acmicpc.net/problem/1699 // 제곱수의 합 #include #include using namespace std; int dp[100001] = { 0, }; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int N; cin >> N; for (int i = 1; i
#include #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int i = 0, sum = 0, tmp = 1, flag = 0; stack s; string str; cin >> str; while (str[i] != 0) { if (str[i] == '(') { s.push(str[i]); tmp *= 2; } else if (str[i] == '[') { s.push(str[i]); tmp *= 3; } else if (str[i] == ')' && (s.empty() || s.top() != '(')) { flag = 1; break; } el..
#include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int N, queue[100001], a, size = 0; char cmd[6] = { 0, }; cin >> N; for (int i = 0; i > cmd; if (!strcmp(cmd, "push")) { cin >> a; queue[size] = a; size++; } else if (!strcmp(cmd, "pop")) { if (!size) { cout
#include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int N, stack[100001] = { 0, }, top = -1, a; char cmd[6] = { 0, }; cin >> N; for (int i = 0; i > cmd; if (!strcmp(cmd, "push")) { cin >> a; top++; stack[top] = a; } else if (!strcmp(cmd, "pop")) { if (top == -1) { cout
#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long N, F[10001] = { 0,1, }, sum = 0; cin >> N; for (int i = 0; i < N; i++) { F[i + 2] = F[i] + F[i + 1]; } cout