Skip to content

Commit 0f9ed93

Browse files
authored
Create 36_codechef_Encoding_message.cpp
1 parent c6734aa commit 0f9ed93

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

36_codechef_Encoding_message.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//
2+
// main.cpp
3+
// Lecture 36
4+
//
5+
// Created by Prince Kumar on 17/04/19.
6+
// Copyright © 2019 Prince Kumar. All rights reserved.
7+
//
8+
// CODE-CHEF
9+
10+
// --- ** Problems on Encoding Message ** --- //
11+
12+
13+
#include <iostream>
14+
using namespace std;
15+
int main()
16+
{
17+
int T; cin>>T;
18+
while(T--)
19+
{
20+
int n; cin>>n; // lenght of string
21+
string s; cin>>s;
22+
23+
// 1st step of encoding
24+
if(n%2==0)
25+
{
26+
// even
27+
for(int i=0;i<n;i=i+2) // len= 6 ; index -> 0 to 5
28+
{
29+
char z = s[i+1]; // z='h'
30+
s[i+1] = s[i] ; //
31+
s[i]=z;
32+
}
33+
}
34+
else
35+
{
36+
// odd
37+
for(int i=0;i<n-1;i=i+2)
38+
{
39+
char z = s[i+1]; // z='h'
40+
s[i+1] = s[i] ; //
41+
s[i]=z;
42+
}
43+
}
44+
45+
// 2nd stage of encoding
46+
47+
for(int i=0;i<n;i++)
48+
{
49+
char c = s[i]; // recent character // b --> 98
50+
//int index = s[i]-97;
51+
int index = c-97; // 1
52+
int req = 25-index; // 24
53+
54+
// range 97 to 122
55+
req = req + 97;
56+
char y = (char)req; // real ASCII code
57+
cout<<y;
58+
59+
}
60+
cout<<endl;
61+
62+
63+
64+
}
65+
}
66+
67+
68+
69+

0 commit comments

Comments
 (0)