제출 #149073

#제출 시각아이디문제언어결과실행 시간메모리
149073티셔츠 콜렉터 (#200)HicCup (FXCUP4_hiccup)C++17
컴파일 에러
0 ms0 KiB
#include "hiccup.h" int maximumHiccup (int* levelCountArray, int level) { if (levelCountArray[level] == 0) { return 0; } else { int childHiccup = maximumHiccup(levelCountArray, level + 1); if (childHiccup % 2 == 0) { return max(childHiccup, levelCountArray[level]); } else { return 0; } } } int HicCup(std::string S) { int N = S.size(); int levelArray[N] = {-1}; int level = 1; int firstCharacterIndex = 0; char previousCharacter = ' '; // 첫번째 캐릭터 찾는 루프 for (int index = 0; index < N; index++) { if (S[index] != '!') { previousCharacter = S[index]; levelArray[index] = 1; firstCharacterIndex = index; break; } levelArray[index] = -1; } // 나머지 루프 for (int index = firstCharacterIndex + 1; index < N; index++) { if (S[index] == '!') { levelArray[index] = -1; continue; } if (previousCharacter != S[index]) { levelArray[index] = level; } if (previousCharacter == S[index]) { if (previousCharacter == 'H') levelArray[index] = ++level; if (previousCharacter == 'C') levelArray[index] = --level; } previousCharacter = S[index]; } int levelCountArray[N] = {0}; for(int i=0; i<N; i++) { cout << levelArray[i] << ' '; } for (int i= 0; i < N ; i++){ if (levelArray[i] != -1) levelCountArray[levelArray[i]]++; } int max = maximumHiccup(levelCountArray, 1); if (max % 2 == 0) { return max; } else { return -1; } }

컴파일 시 표준 에러 (stderr) 메시지

hiccup.cpp: In function 'int maximumHiccup(int*, int)':
hiccup.cpp:9:20: error: 'max' was not declared in this scope
             return max(childHiccup, levelCountArray[level]);
                    ^~~
hiccup.cpp:9:20: note: suggested alternative:
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/string:40,
                 from hiccup.h:2,
                 from hiccup.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:265:5: note:   'std::max'
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:53:9: error: 'cout' was not declared in this scope
         cout << levelArray[i] << ' ';
         ^~~~