-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncryption_MK.cpp
More file actions
75 lines (65 loc) · 1.39 KB
/
Encryption_MK.cpp
File metadata and controls
75 lines (65 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
// Complete the encryption function below.
/*string encryption(string s) {
}*/
int main()
{
ofstream fout(getenv("OUTPUT_PATH"));
string str;
getline(cin, str);
std::string::iterator end_pos = std::remove(str.begin(), str.end(), ' ');
str.erase(end_pos, str.end());
int a, b, row, col;
float z;
int L = str.length();
z = sqrt(str.length());
b = ceil(z);
a = b - 1;
if((a * a) >= L) {
row = a;
col = a;
}
else if((a * b) >= L) {
row = a;
col = b;
}
else {
row = b;
col = b;
}
int ctr = L;
int m = 0;
char carray[row][col];
for(int i = 0; i < row; i++) {
if(ctr == 0)
break;
for(int j = 0; j < col; j++) {
carray[i][j] = str[m];
m++;
ctr--;
}
}
string result;
int index = 0;
for(int i = 0; i < col; i++) {
for(int j = 0; j < row; j++) {
if(carray[j][i] == '\0')
break;
else {
fout << carray[j][i];
cout << carray[j][i];
}
}
fout << " ";
cout << " ";
}
cout << result;
//string result = encryption(s);
//fout << result << "\n";
fout.close();
return 0;
}