-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
96 lines (77 loc) · 2.05 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <QCoreApplication>
#include <QVector>
#include <QHash>
#include <QRegularExpression>
#include <iostream>
int main(int, char *[])
{
QStringList list;
std::string in;
while(std::getline(std::cin, in))
{
list << QString::fromStdString(in);
}
QHash<int, int> linePadding;
QVector<int> colCount;
const QString delimiter = "<<";
// Split lines
foreach(const QString& line, list)
{
QStringList parts = line.split(delimiter);
int count = 0;
// Get the tab size of the line from the first part
linePadding[line.indexOf(QRegularExpression("\\S"))]++;
foreach(const QString& part, parts)
{
QString simp = part.trimmed();
int length = simp.length();
if(colCount.size() <= count)
{
colCount.push_back(length);
}
else
{
if(colCount.at(count) < length)
colCount[count] = length;
}
count++;
}
}
// Get the max occurence in linePadding
int tabSize = 0;
int max = 0;
auto i = linePadding.constBegin();
while (i != linePadding.end())
{
if(i.value() > max)
{
max = i.value();
tabSize = i.key();
}
++i;
}
// Construct output
foreach(const QString& line, list)
{
QStringList parts = line.split(delimiter);
int count = 0;
std::cout << QString().fill(' ', tabSize).toStdString();
foreach(const QString& part, parts)
{
QString out = part.trimmed();
// Not Last part
if(count+1 < parts.size())
{
out = out.leftJustified(colCount[count], ' ');
}
std::cout << out.toStdString();
if(count+1 < parts.size())
{
std::cout << " " << delimiter.toStdString() << " ";
}
count++;
}
std::cout << std::endl;
}
return 0;
}