@@ -39,18 +39,18 @@ void rotateClockwise(std::vector<std::vector<char> > &v, int layer) {
39
39
int right = n - 1 - layer;
40
40
41
41
if (left >= right) {
42
- return ;
42
+ return ;
43
43
}
44
44
45
45
int d = 0 ;
46
46
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;
52
52
53
- d++;
53
+ d++;
54
54
}
55
55
rotateClockwise (v, layer + 1 );
56
56
}
@@ -64,33 +64,33 @@ void rotateCounterClockwise(std::vector<std::vector<char> > &v, int layer) {
64
64
int right = n - 1 - layer;
65
65
66
66
if (left >= right) {
67
- return ;
67
+ return ;
68
68
}
69
69
70
70
int d = 0 ;
71
71
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;
77
77
78
- d++;
78
+ d++;
79
79
}
80
80
rotateClockwise (v, layer + 1 );
81
81
}
82
82
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 ());
85
85
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
+ }
92
92
93
- return v;
93
+ return v;
94
94
}
95
95
96
96
char FILLER_CHAR = (char ) 11 ;
@@ -104,7 +104,7 @@ class CodeSqStrings {
104
104
std::vector temp (n, std::vector<char >(n, FILLER_CHAR));
105
105
106
106
// fill strng into temp
107
- for (int i = 0 ; i < strng.length (); ++i) {
107
+ for (auto i = 0 ; i < strng.length (); ++i) {
108
108
int y = i / n;
109
109
int x = i % n;
110
110
temp[y][x] = strng[i];
@@ -117,18 +117,18 @@ class CodeSqStrings {
117
117
}
118
118
119
119
static std::string decode (const std::string &strng) {
120
- auto temp = toCharsVectors (strng);
120
+ auto temp = toCharsVectors (strng);
121
121
122
- // rotate 90 degrees counter-clockwise
123
- rotateCounterClockwise (temp, 0 );
122
+ // rotate 90 degrees counter-clockwise
123
+ rotateCounterClockwise (temp, 0 );
124
124
125
- auto s = joinVectorCharVector (temp, " " );
125
+ auto s = joinVectorCharVector (temp, " " );
126
126
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
+ }
133
133
}
134
134
};
0 commit comments