티스토리 뷰

백준

백준 소스코드 [C++] 3986 좋은 단어

Hani_Levenshtein 2020. 8. 27. 19:26

https://www.acmicpc.net/problem/3986

 

3986번: 좋은 단어

이번 계절학기에 심리학 개론을 수강 중인 평석이는 오늘 자정까지 보고서를 제출해야 한다. 보고서 작성이 너무 지루했던 평석이는 노트북에 엎드려서 꾸벅꾸벅 졸다가 제출 마감 1시간 전에 �

www.acmicpc.net

백준 소스코드 [C++] 3986 좋은 단어

#include <iostream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
int main() {
	int n,good=0;
	cin >> n;
	string xx;
	stack <char>s;
	for (int i = 0;i < n;i++) {
		cin >> xx;
		for (int j = 0;j < (int)xx.length();j++) {
			if (s.empty() == true) s.push(xx[j]);
			else if (s.top() == xx[j]) s.pop();
			else  s.push(xx[j]);
		}
		if (s.size() == 0) good++;
		while (s.empty() != true) s.pop();
	}
	cout << good;
	return 0;
}
댓글