Skip to content

Instantly share code, notes, and snippets.

@MinecraftFuns
Created November 15, 2020 11:38
Show Gist options
  • Save MinecraftFuns/e6fe87c1cc91ccfa99db7b8adcb9dff9 to your computer and use it in GitHub Desktop.
Save MinecraftFuns/e6fe87c1cc91ccfa99db7b8adcb9dff9 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
#define alive std::cout << "$LINE @" << __LINE__ << " ALIVE" << std::endl
#define watch(var) std::cout << "$ LINE @" << __LINE__ << " FUN @" << __FUNCTION__ \
<< " VAR @" << (#var) << ": " << (var) << std::endl
using namespace std;
typedef int i32;
typedef unsigned int u32;
typedef long long i64;
typedef unsigned long long u64;
typedef double f64;
typedef long double f128;
typedef pair<int, int> pii;
template <typename Tp>
inline void read(Tp &x)
{
x = 0;
bool neg = false;
char c = getchar();
for (; !isdigit(c); c = getchar())
{
if (c == '-')
{
neg = true;
}
}
for (; isdigit(c); c = getchar())
{
x = x * 10 + c - '0';
}
if (neg)
{
x = -x;
}
}
const int N = 2e5 + 5;
char str[N];
inline void solve()
{
auto indent = [](const int &num) {
for (int i = 0; i < num; ++i)
{
putchar(' ');
}
};
static char c = ' ';
auto emptyChar = [&]() {
return c == ' ' || c == '\t' || c == '\n';
};
auto passEmptyChar = [&]() {
for (; emptyChar(); c = getchar())
;
};
int layer = 0;
int len;
auto scanfTag = [&]() {
len = 0;
for (; c != '>'; c = getchar())
{
str[len++] = c;
}
str[len++] = '>';
c = getchar();
str[len] = '\0';
};
auto scanfText = [&]() {
len = 0;
for (; !emptyChar() && c != '<'; c = getchar())
{
str[len++] = c;
}
str[len] = '\0';
};
auto workTag = [&]() {
scanfTag();
if (str[1] == '/')
{
--layer;
indent(layer);
printf("%s\n", str);
return strcmp(str, "</html>") == 0 ? -1
: 0;
}
if (str[len - 2] == '/')
{
indent(layer);
printf("%s\n", str);
}
else
{
indent(layer);
++layer;
printf("%s\n", str);
}
return 0;
};
auto workText = [&]() {
indent(layer);
bool first = true;
for (; c != '<'; passEmptyChar())
{
scanfText();
if (!first)
{
putchar(' ');
}
printf("%s", str);
first = false;
}
putchar('\n');
};
while (true)
{
passEmptyChar();
if (c == '<')
{
if (workTag() == -1)
{
return;
}
}
else
{
workText();
}
}
}
int main()
{
int T;
read(T);
for (int cas = 1; cas <= T; ++cas)
{
printf("Case #%d:\n", cas);
solve();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment