Skip to content

Instantly share code, notes, and snippets.

@faresbakhit
Created March 12, 2024 21:10
Show Gist options
  • Save faresbakhit/8a216d583b77e778360cb1ee49f224ec to your computer and use it in GitHub Desktop.
Save faresbakhit/8a216d583b77e778360cb1ee49f224ec to your computer and use it in GitHub Desktop.
#include <cmath>
#include <iostream>
using namespace std;
int main()
{
string s;
cout << "Plain text: ";
getline(cin, s);
for (auto it = s.begin(); it != s.end();) {
char c = tolower(*it);
if (c >= 'a' && c <= 'z') {
*it = c;
it++;
} else {
s.erase(it);
}
}
for (int i = 0, t = ceil(s.size() / 4.0); i != t; ++i) {
cout << s[4 * i];
}
for (int i = 0, t = s.size() / 2; i != t; ++i) {
cout << s[2 * i + 1];
}
for (int i = 0, t = ceil(max((int)s.size() - 2, 0) / 4.0); i != t; ++i) {
cout << s[4 * i + 2];
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment