Skip to content

Instantly share code, notes, and snippets.

@luckypapa
Created October 5, 2015 07:01
Show Gist options
  • Save luckypapa/4f503864670c9adb89b5 to your computer and use it in GitHub Desktop.
Save luckypapa/4f503864670c9adb89b5 to your computer and use it in GitHub Desktop.
//https://algospot.com/judge/problem/read/ENCRYPT
#include <string>
#include <vector>
#include <iostream>
using namespace std;
string encryptString(const string &str) {
int length = str.length();
string encryptedStr;
vector<string> v;
for (int i = 0; i < length; i += 2) {
v.push_back(str.substr(i, 1));
}
for (int i = 1; i < length; i += 2) {
v.push_back(str.substr(i, 1));
}
for (vector<string>::iterator it = v.begin(); it != v.end(); it++) {
encryptedStr += *it;
}
return encryptedStr;
}
int main(void) {
int testCount, i;
string str;
vector<string> v;
cin >> testCount;
for (i = 0; i < testCount; i++) {
cin >> str;
if (str.length() > 100)
return 1;
v.push_back(encryptString(str));
}
for (vector<string>::iterator it = v.begin(); it != v.end(); it++) {
cout << *it << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment