728x90

Stack 4

백준 c++ 15815 천재 수학자 성필

15815 천재 수학자 성필 문제풀이 #include #include using namespace std; void fast_io(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int main() { fast_io(); string str; stack s; cin >> str; int i = 0, res = 0; while (str[i] != '\0') { if (isdigit(str[i])) s.push(str[i] - 48); else { int b = s.top(); s.pop(); int a = s.top(); s.pop(); if (str[i] == '+') s.push(a + b..

백준 c++ 3986 좋은 단어

3986 좋은 단어 문제 풀이 #include #include using namespace std; void fast_io(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int main() { fast_io(); int n, res = 0; cin >> n; while (n--)//입력받은만큼 돈다 { string str; stack s; cin >> str;//문자열 입력받음 s.push(str[0]); //하나를 넣은상태로 시작 for (int i = 1; i < str.size(); i++) { if (!s.empty() && str[i] == s.top()) {//비어있지 않고, 현재 char 가 스택의 top..

728x90