목록Algorithm/C++ (148)
cgy12306
// https://www.acmicpc.net/problem/1912 // 연속합 #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, dp[100001] = { 0, }, arr[100001] = { 0, }; cin >> n; for (int i = 0; i > arr[i]; } dp[0] = arr[0]; int sum = dp[0]; for (int i = 1; i < n; i++) { dp[i] = max(dp[i - 1] + arr[i], arr[i]); sum = max(sum, dp[i]); } cout
// https://www.acmicpc.net/problem/9461 // 파도반 수열 #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long dp[101]; int n, a; cin >> a; for (int j = 0; j > n; dp[1] = 1; dp[2] = 1; dp[3] = 1; dp[4] = 2; dp[5] = 2; for (int i = 6; i
// https://www.acmicpc.net/problem/2193 // 이친수 #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, dp[91]; cin >> n; dp[1] = 1; dp[2] = 1; for (int i = 3; i
// 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