Advertisement
Sitleman

Untitled

Nov 6th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <fstream>
  5. #include <queue>
  6. #include <map>
  7. #include <set>
  8. #include <unordered_set>
  9. #include <tuple>
  10. #include <unordered_map>
  11. #include <deque>
  12. #include <cmath>
  13. #include <string>
  14. #include <stdio.h>
  15. using namespace std;
  16.  
  17. bool sym(char c){
  18. return c == ',' ||
  19. c == '.' ||
  20. c == '?' ||
  21. c == '!' ||
  22. c == ':' ||
  23. c == '-' ||
  24. c == '\'' ||
  25. c == ' ';
  26. }
  27.  
  28. int main() {
  29. ios::sync_with_stdio(0);
  30. cin.tie(0);
  31. cout.tie(0);
  32. ifstream cin("input.txt");
  33. ofstream cout("output.txt");
  34. int w, b;
  35. cin >> w >> b;
  36. int cur_w = 0;
  37. bool cur_b = true;
  38. string s;
  39. bool k = false;
  40. getline(cin, s);
  41. while (getline(cin, s)){
  42. int l = 0, r = 0;
  43. if (s.size() == 0) cur_b = true;
  44. if (s.size() > 0 && cur_b) {
  45. cur_b = false;
  46. if (k) cout << "\n";
  47. for (int i = 1; i < b; i++){
  48. cout << " ";
  49. }
  50. cur_w = b;
  51. k = true;
  52. }
  53.  
  54. while (r < s.size()){
  55. while (r < s.size() && !sym(s[r])) r++;
  56. while (r < s.size() && sym(s[r]) && s[r] != ' ') r++;
  57. if (r - l + 1 <= w - cur_w){
  58. cout << " ";
  59. cur_w += r - l + 1;
  60. for (int i = l; i < r; i++){
  61. cout << s[i];
  62. }
  63. } else {
  64. cout << '\n';
  65. for (int i = l; i < r; i++){
  66. cout << s[i];
  67. }
  68. cur_w = r - l;
  69. }
  70. l = r;
  71. while (r < s.size() && s[r] == ' ') {r++; l++;}
  72. }
  73.  
  74. }
  75. cout.close();
  76. return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement