We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
string encryption(string s) {
string noSpaces = "";
for (char c : s) {
if (c != ' ') noSpaces += c;
}
int L = noSpaces.length();
int rows = floor(sqrt(L));
int cols = ceil(sqrt(L));
if (rows * cols < L) rows++;
string result = "";
for (int c = 0; c < cols; c++) {
if (c > 0) result += " ";
for (int r = 0; r < rows; r++) {
int idx = r * cols + c;
if (idx < L) {
result += noSpaces[idx];
}
}
}
return result;
Jim and the Jokes
You are viewing a single comment's thread. Return to all comments →
include
include
include
using namespace std;
string encryption(string s) { string noSpaces = ""; for (char c : s) { if (c != ' ') noSpaces += c; }
}
int main() { string s; getline(cin, s); cout << encryption(s) << endl; return 0; }