import sys
whitespaces = ('\n', '\t', ' ')
def parse_line(line, previous_is_amplifying, is_last_line):
line_buff = []
amplifying = False
for idx, c in enumerate(line):
if c in whitespaces:
line_buff.append(c)
else:
amplifying = (c == '#')
break
if not amplifying:
line_buff = []
for i in range(idx, len(line)):
if line[i] in whitespaces:
if amplifying:
line_buff.append(line[i])
else:
line_buff.append(line[i])
if amplifying and is_last_line and line_buff[-1] == '\n':
line_buff.pop()
if not previous_is_amplifying and amplifying:
return '\n' + ''.join(line_buff), amplifying
return ''.join(line_buff), amplifying
lines = sys.stdin.readlines()
out = []
prev = True
for i, line in enumerate(lines):
is_last_line = (i == len(lines)-1)
parsed_line, prev = parse_line(line, prev, is_last_line)
out.append(parsed_line)
print(''.join(out))
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
string line = "";
bool b = false;
while (getline(cin, str)) {
bool good = 0;
for (int i = 0; i < str.length(); i++) {
if (str[i] != '#' && str[i] != ' ') {
break;
}
else if (str[i] == '#') {
good = 1;
break;
}
}
if (good) {
if (b) {
cout << line << "\n";
line = "";
b = 0;
}
cout << str << "\n";
}
else {
b = 1;
for (int i = 0; i < str.length(); i++) {
if (str[i] != ' ') {
line += str[i];
}
}
}
}
if (b) cout << line << "\n";
}/*1692060396.4044921*/
766A - Mahmoud and Longest Uncommon Subsequence | 701B - Cells Not Under Attack |
702A - Maximum Increase | 1656D - K-good |
1426A - Floor Number | 876A - Trip For Meal |
1326B - Maximums | 1635C - Differential Sorting |
961A - Tetris | 1635B - Avoid Local Maximums |
20A - BerOS file system | 1637A - Sorting Parts |
509A - Maximum in Table | 1647C - Madoka and Childish Pranks |
689B - Mike and Shortcuts | 379B - New Year Present |
1498A - GCD Sum | 1277C - As Simple as One and Two |
1301A - Three Strings | 460A - Vasya and Socks |
1624C - Division by Two and Permutation | 1288A - Deadline |
1617A - Forbidden Subsequence | 914A - Perfect Squares |
873D - Merge Sort | 1251A - Broken Keyboard |
463B - Caisa and Pylons | 584A - Olesya and Rodion |
799A - Carrot Cakes | 1569B - Chess Tournament |