Skip to content

Commit fee5bfd

Browse files
committed
feat(Codewars): WIP onlinePlatform/codewars/5kyu/coding_with_squared_strings.cc
1 parent 875e73b commit fee5bfd

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

src/onlinePlatform/codewars/5kyu/coding_with_squared_strings.cc

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ void rotateClockwise(std::vector<std::vector<char> > &v, int layer) {
3939
int right = n - 1 - layer;
4040

4141
if (left >= right) {
42-
return;
42+
return;
4343
}
4444

4545
int d = 0;
4646
while (left + d < right) {
47-
auto t = v[top][left + d];
48-
v[top][left + d] = v[bottom - d][left];
49-
v[bottom - d][left] = v[bottom][right - d];
50-
v[bottom][right - d] = v[top + d][right];
51-
v[top + d][right] = t;
47+
auto t = v[top][left + d];
48+
v[top][left + d] = v[bottom - d][left];
49+
v[bottom - d][left] = v[bottom][right - d];
50+
v[bottom][right - d] = v[top + d][right];
51+
v[top + d][right] = t;
5252

53-
d++;
53+
d++;
5454
}
5555
rotateClockwise(v, layer + 1);
5656
}
@@ -64,33 +64,33 @@ void rotateCounterClockwise(std::vector<std::vector<char> > &v, int layer) {
6464
int right = n - 1 - layer;
6565

6666
if (left >= right) {
67-
return;
67+
return;
6868
}
6969

7070
int d = 0;
7171
while (left + d < right) {
72-
auto t = v[top][left + d];
73-
v[top][left + d] =v[top + d][right];
74-
v[top + d][right] = v[bottom][right - d];
75-
v[bottom][right - d] = v[bottom - d][left];
76-
v[bottom - d][left] = t;
72+
auto t = v[top][left + d];
73+
v[top][left + d] = v[top + d][right];
74+
v[top + d][right] = v[bottom][right - d];
75+
v[bottom][right - d] = v[bottom - d][left];
76+
v[bottom - d][left] = t;
7777

78-
d++;
78+
d++;
7979
}
8080
rotateClockwise(v, layer + 1);
8181
}
8282

83-
std::vector<std::vector<char>> toCharsVectors(const std::string &s) {
84-
int n = (int) std::sqrt(s.length());
83+
std::vector<std::vector<char> > toCharsVectors(const std::string &s) {
84+
int n = (int) std::sqrt(s.length());
8585

86-
std::vector<std::vector<char>> v;
87-
for (int i = 0; i < s.length(); i += n) {
88-
auto ss = s.substr(i, n);
89-
std::vector<char> chars(ss.begin(), ss.end());
90-
v.push_back(chars);
91-
}
86+
std::vector<std::vector<char> > v;
87+
for (auto i = 0; i < s.length(); i += n) {
88+
auto ss = s.substr(i, n);
89+
std::vector<char> chars(ss.begin(), ss.end());
90+
v.push_back(chars);
91+
}
9292

93-
return v;
93+
return v;
9494
}
9595

9696
char FILLER_CHAR = (char) 11;
@@ -104,7 +104,7 @@ class CodeSqStrings {
104104
std::vector temp(n, std::vector<char>(n, FILLER_CHAR));
105105

106106
// fill strng into temp
107-
for (int i = 0; i < strng.length(); ++i) {
107+
for (auto i = 0; i < strng.length(); ++i) {
108108
int y = i / n;
109109
int x = i % n;
110110
temp[y][x] = strng[i];
@@ -117,18 +117,18 @@ class CodeSqStrings {
117117
}
118118

119119
static std::string decode(const std::string &strng) {
120-
auto temp = toCharsVectors(strng);
120+
auto temp = toCharsVectors(strng);
121121

122-
// rotate 90 degrees counter-clockwise
123-
rotateCounterClockwise(temp, 0);
122+
// rotate 90 degrees counter-clockwise
123+
rotateCounterClockwise(temp, 0);
124124

125-
auto s = joinVectorCharVector(temp, "");
125+
auto s = joinVectorCharVector(temp, "");
126126

127-
std::string::size_type loc = s.find( FILLER, 0 );
128-
if( loc != std::string::npos ) {
129-
return s;
130-
} else {
131-
return s.substr(0, loc);
132-
}
127+
std::string::size_type loc = s.find(FILLER, 0);
128+
if (loc != std::string::npos) {
129+
return s;
130+
} else {
131+
return s.substr(0, loc);
132+
}
133133
}
134134
};

0 commit comments

Comments
 (0)