-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCheatingExam.cpp
89 lines (87 loc) · 1.98 KB
/
CheatingExam.cpp
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//author @Nishant
/*
IAMSMARTERTHANYOU
IE U
ATRO
MRTY
SAHN
M A
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
string encoded;
cin >> encoded;
if(encoded.length() <= 0 || n<=0){
return 0;
}
if(n==1){
cout << encoded;
return 0;
}
int len = (encoded.length()-1)/(n-1);
if(len%2 != 0){
len += 1;
}
char code[n][len];
int k = 0;
for(int i=0; i<n; i++){
for(int j=0; j<len; j++){
if(i==0 && j==0){
code[i][i] = encoded.at(k++);
}
if(i==0 && j>0){
if(j%2!=0){
code[i][j] = encoded.at(k++);
}
}
if(i>0 && i<n-1){
code[i][j] = encoded.at(k++);
}
if(i==n-1){
if(j%2 == 0){
code[i][j] = encoded.at(k++);
}
}
}
}
// for(int i=0;i<n;i++){
// cout << endl;
// for(int j=0;j<len;j++)
// cout << code[i][j] << "\t";
// }
vector<char> ans;
for(int j=0; j<len; j++){
if(j%2==0){
if(j==0){
for(int i=0; i<n; i++){
//if(code[i][j]!='X' && (code[i+1][j]!='X' || code[i][j+1]!='X')){
//if(code[i][j]!='X'){
ans.push_back(code[i][j]);
//}
}
}else{
for(int i=1; i<n; i++){
//if(code[i][j]!='X'){
ans.push_back(code[i][j]);
//}
}
}
}else{
for(int i=n-2; i>=0; i--){
//if(code[i][j]!='X'){
ans.push_back(code[i][j]);
//}
}
}
}
int temp = ans.size()-1;
while(ans.at(temp) == 'X'){
temp--;
}
for(int i=0; i<=temp; i++){
cout << ans.at(i);
}
}