forked from itskartike910/Calculator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBalancedString.cpp
More file actions
85 lines (53 loc) · 1.4 KB
/
BalancedString.cpp
File metadata and controls
85 lines (53 loc) · 1.4 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
76
77
78
79
80
81
82
83
84
85
#include <istream>
#include <bits/stdc++.h>
using namespace std;
string BalncedString(int N){
int n=N,n1=N,n2=N;
int i=0;
string s1,s2;
if(N%2==0){
if(n<26){
for(int j=0;j<n/2;j++){
char ch='a'+j;
s1=s1+ch;
}
for(int j=0;j<n/2;j++){
char ch1='z'-j;
s2=ch1+s2;
}
string s3=s1+s2;
return s3;
}
else
{ string s3="";
int r=(n/2)%13;
int d=(n/2)%13;
for(int p=0;p<d;p++){
for(int j=0;j<13;j++){
char ch='a'+j;
s1=s1+ch;
char ch1='z'-j;
s2=ch1+s2;
}
s3=s3+s1+s2;
s1="";
s2="";
}
for(int j=0;j<r;j++){
char ch='a'+j;
s1=s1+ch;
char ch1='z'-j;
s2=ch1+s2;
}
s3=s3+s1+s2;
return s3;
}
}
else{
}
}
int main()
{
cout<<BalncedString(100);
return 0;
}