[GESP202609 三级]分割字符串
2026-09-19 20:45:33
发布于:江苏
1阅读
0回复
0点赞
点我点我😁点我点我😁点我点我😁点我点我😁
Hi~ o( ̄▽ ̄)ブ
#include <cstdio>
static char buf[1024];
static char out_buf[2048];
int out_pos = 0;
inline void push_char(char c) {
out_buf[out_pos++] = c;
}
inline void push_str(const char* s, int len) {
for (int i = 0; i < len; ++i) {
out_buf[out_pos++] = s[i];
}
}
int main() {
if (!fgets(buf, sizeof(buf), stdin)) return 0;
int n = 0;
while (buf[n] != '\0' && buf[n] != '\n' && buf[n] != '\r') {
n++;
}
int pos = 0;
int k = 1;
while (pos < n) {
int start = pos;
bool found = false;
while (pos <= n - k) {
bool is_all_spaces = true;
for (int j = 0; j < k; ++j) {
if (buf[pos + j] != ' ') {
is_all_spaces = false;
break;
}
}
if (is_all_spaces) {
found = true;
break;
}
pos++;
}
if (found) {
if (pos > start) {
push_str(buf + start, pos - start);
}
push_char('\n');
pos += k;
k++;
} else {
if (n > start) {
push_str(buf + start, n - start);
}
push_char('\n');
break;
}
}
fwrite(out_buf, 1, out_pos, stdout);
return 0;
}
这里空空如也







有帮助,赞一个