알고리즘/BOJ

백준 6581번 HTML

꾸준함. 2018. 11. 3. 03:14

문제 링크입니다: https://www.acmicpc.net/problem/6581


문자열 파싱 문제였습니다.

해당 문자열이 같은 줄에 있는지 없는지를 판단해야하는 것만 주의한다면 어렵지 않게 풀 수 있는 문제인 것 같습니다.


#include <iostream>

#include <string>

using namespace std;

 

int main(void)

{

        ios_base::sync_with_stdio(0);

        cin.tie(0);

        string s;

        int sum = 0;

        bool sameline = false;

        while (cin >> s)

        {

                 if (s == "<br>")

                 {

                         cout << "\n";

                         sum = 0;

                 }

                 else if (s == "<hr>")

                 {

                         if (!sum)

                         {

                                 for (int i = 0; i < 80; i++)

                                          cout << "-";

                                 cout << "\n";

                         }

                         else

                         {

                                 sum = 0;

                                 cout << "\n";

                                 for (int i = 0; i < 80; i++)

                                          cout << "-";

                                 cout << "\n";

                         }

                 }

                 else

                 {

                         int len = s.length();

                         if (!sum)

                         {

                                 sum = len;

                                 cout << s;

                                 sameline = true;

                         }

                         else if (sum + len + 1 <= 80)

                         {

                                 if (sameline)

                                 {

                                          cout << " ";

                                          sum += 1;

                                 }

                                 sum += len;

                                 cout << s;

                                 if (sum == 80)

                                 {

                                          cout << "\n";

                                          sum = 0;

                                          sameline = false;

                                 }

                         }

                         else

                         {

                                 cout << "\n";

                                 sum = len;

                                 sameline = true;

                                 cout << s;

                         }

                 }

        }

        return 0;

}


개발환경:Visual Studio 2017


지적, 조언, 질문 환영입니다! 댓글 남겨주세요~

반응형

'알고리즘 > BOJ' 카테고리의 다른 글

백준 2617번 구슬 찾기  (0) 2018.11.04
백준 2851번 슈퍼 마리오  (0) 2018.11.04
백준 12761번 돌다리  (0) 2018.11.02
백준 2331번 반복수열  (5) 2018.11.02
백준 2038번 골롱 수열  (0) 2018.11.02