Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <fstream>
- #include <queue>
- #include <map>
- #include <set>
- #include <unordered_set>
- #include <tuple>
- #include <unordered_map>
- #include <deque>
- #include <cmath>
- #include <string>
- #include <stdio.h>
- using namespace std;
- bool sym(char c){
- return c == ',' ||
- c == '.' ||
- c == '?' ||
- c == '!' ||
- c == ':' ||
- c == '-' ||
- c == '\'' ||
- c == ' ';
- }
- int main() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- ifstream cin("input.txt");
- ofstream cout("output.txt");
- int w, b;
- cin >> w >> b;
- int cur_w = 0;
- bool cur_b = true;
- string s;
- bool k = false;
- getline(cin, s);
- while (getline(cin, s)){
- int l = 0, r = 0;
- if (s.size() == 0) cur_b = true;
- if (s.size() > 0 && cur_b) {
- cur_b = false;
- if (k) cout << "\n";
- for (int i = 1; i < b; i++){
- cout << " ";
- }
- cur_w = b;
- k = true;
- }
- while (r < s.size()){
- while (r < s.size() && !sym(s[r])) r++;
- while (r < s.size() && sym(s[r]) && s[r] != ' ') r++;
- if (r - l + 1 <= w - cur_w){
- cout << " ";
- cur_w += r - l + 1;
- for (int i = l; i < r; i++){
- cout << s[i];
- }
- } else {
- cout << '\n';
- for (int i = l; i < r; i++){
- cout << s[i];
- }
- cur_w = r - l;
- }
- l = r;
- while (r < s.size() && s[r] == ' ') {r++; l++;}
- }
- }
- cout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement