-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPA5_A.cpp
More file actions
68 lines (46 loc) · 1.2 KB
/
Copy pathPA5_A.cpp
File metadata and controls
68 lines (46 loc) · 1.2 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
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
int n;
cin>> n ;
cout<< endl;
char g[n+1] ;
for(int i=0;i<n;i++){
cin>>g[i];
}
g[n]='\0';
vector<vector<string>> dp(n , vector<string>(n,""));
vector<vector<int>> dp1(n , vector<int>(n,0));
//prniting the subgardens
for(int i=0; i<n;i++){
for(int j=i; j<n;j++){
for(int k=i;k<=j;k++){
//cout<<g[k];
dp[i][j]+=g[k];
cout<<dp[i][j][dp[i][j].size()-1];
}
cout<<" ";
}
cout<<endl;
}
for(int i=0; i<n;i++){
for(int j=i; j<n;j++){
int m=0,k,l=0;
string ch=dp[i][j];
k=ch.size()-1;
//printing the number of replacement ,comparing the subgarden flower
while(l<k){
if(ch[l]!=ch[k]){
ch[l]=ch[k];//replacing the different element
m++;
l++,k--;
}
}
cout<<m<< " "<<ch<<" "; //both the replacement and ch printing
}
cout<<endl;
}
return 0;
}