본문 바로가기

USACO/Bronze

백준 18322 Word Processor (USACO January 2020 Bronze 1번)

문제 링크: https://www.acmicpc.net/problem/18322

 

18322번: Word Processor

Including "hello" and "my", the first line contains 7 non-space characters. Adding "name" would cause the first line to contain $11>7$ non-space characters, so it is placed on a new line.

www.acmicpc.net

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <bits/stdc++.h>
using namespace std;
 
int n, k;
string s[101];
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
    cin >> n >> k;
    for(int i = 0; i < n; i++cin >> s[i];
 
    int len = 0;
    for(int i = 0; i < n; i++) {
        len += s[i].size();
        if(len <= k) {
            cout << s[i] << ' ';
        }
        else {
            cout << '\n' << s[i] << ' ';
            len = s[i].size();
        }
    }
    return 0;
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter