post image post image post image post image post image post image post image post image

www.acmicpc.net/problem/6581

 

6581번: HTML

원래의 HTML 문서가 입력으로 주어진다. 이 텍스트는 단어와 HTML 태그들로 이루어져 있으며, 태그는 한 개 이상의 공백문자나 탭, 개행 문자 등으로 구분된다. 단어는 연속된 알파벳, 숫자, 또는

www.acmicpc.net

단순 문자열 파싱 문제이다. 재채점되어서 틀렸었는데, 원인은 문장 제일 끝에 붙은 공백때문이었던 것 같다.

 

#include <iostream>
#include <string>

using namespace std;

#define PRINT cout << tmp; line_length += tmp.size()
#define NEXTLINE cout << '\n'; line_length = 0

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string tmp = " ";
	int line_length = 0;

	while (cin >> tmp) {
		if (tmp.compare("<br>") == 0) {
			NEXTLINE;
		}
		else if (tmp.compare("<hr>") == 0) {
			if (line_length != 0) { NEXTLINE; }
			for (int i = 0; i < 80; i++) {
				cout << '-';
			}
			NEXTLINE;
		}
		else {
			if (line_length + tmp.size() < 80) {
				if (line_length != 0) { cout << ' '; line_length++; }
				PRINT;
			}
			else {
				NEXTLINE;
				PRINT;
			}
		}
	}

	return 0;
}
메모리: 2020 kb 시간: 0 ms

+ Recent posts