알고리즘

    [백준 17609번-C++] 회문

    http://acmicpc.net/problem/17609 {코드} #include #include using namespace std; string s; int isPalindrome(int left, int right, bool testPseudo) { while (left < right) { if (s[left] != s[right]) { if (testPseudo) { if (isPalindrome(left+1, right, false) == 0 || isPalindrome(left, right-1, false) == 0) return 1; } return 2; } left++; right--; } return 0; } int main() { ios_base::sync_with_stdio(fals..

    [백준 17608번-C++] 막대기

    http://acmicpc.net/problem/17608 {코드} #include using namespace std; int main() { int rods[100001], n; scanf("%d", &n); for (int i=0; i=0; i--) { if (max < rods[i]) { max = rods[i]; cnt++; } } printf("%d\n", cnt); } {설명} 이 문제에서는 모든 막대기를 일렬로 나열한 후 오른쪽에서 보기 때문에 어떤 막대기는 오른쪽에 있는 모든 막대기보다 크면 보이게 되는 것입니다. 우선, 가장 오른쪽의 막대기, 즉, 마지막 인덱스의 막대기는 무조건 보이므로 이를 max값으로 잡고 왼쪽으로 하나씩 이동하며 만약 이 max값보다 막대기의 길이가 더 크면 ma..

    [백준 9012번-C++] 괄호

    http://acmicpc.net/problem/9012 {코드} #include #include #include using namespace std; int main() { int n; string s, ans = ""; stack st; cin >> n; while (n--) { cin >> s; stack st; for (const char &c : s) { if (c == '(') { st.push(c); } else { if (!st.empty()) { st.pop(); } else { st.push('('); break; } } } if (!st.empty()) { ans += "NO\n"; } else { ans += "YES\n"; } } cout

    [백준 9093번-C++/파이썬] 단어 뒤집기

    http://acmicpc.net/problem/9093 {코드} #include #include #include using namespace std; int main() { int n; string s; stack st; cin >> n; cin.ignore(); while (n--) { getline(cin, s); s += ' '; for (const char&c : s) { if (c == ' ') { while (!st.empty()) { cout

    {프로젝트 오일러/Project Euler} 11. 격자 속 연속된 수의 곱의 최댓값

    한국어/Hackerrank - 한국어 버전과 문제가 다를 수 있습니다. 채점은 Hackerrank를 추천합니다. 격자의 크기 = 20x20, 0