-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05_String_22_2.cpp
More file actions
81 lines (80 loc) · 1.86 KB
/
Copy path05_String_22_2.cpp
File metadata and controls
81 lines (80 loc) · 1.86 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
#include <bits/stdc++.h>
using namespace std;
/*int calcstr(string x, string y){
int maxdiff = x.length()-y.length(), maxcount=0,diff=0;
for(int i=0;i<maxdiff;i++){
int count=0;
int move=0;
for(int j=0;j<y.length();j++){
if(y[j]==x[j+i]){
count++;
}
}
if(count>=maxcount){
maxcount=count;
diff=i;
}
}
for(int i=0;i<diff;i++){
y = "-" + y;
}
}
*/
int main(){
string a,b;
cin >> a;
cin >> b;
int alen = a.length(), blen = b.length(),maxcounta=0,maxdiff,maxcountb=0,diffa=0,diffb=0;
if(alen>=blen) maxdiff=alen-blen;
else maxdiff=blen-alen;
// if(alen>blen){
for(int i=0;i<=alen;i++){
int count=0;
for(int j=0;j<b.length();j++){
if(b[j]==a[j+i]){
count++;
}
}
if(count>maxcountb){
maxcountb=count;
diffb=i;
}
}
// for(int i=0;i<diff;i++){
// b = "-" + b;
// }
// } else{
for(int i=0;i<=blen;i++){
int count=0;
for(int j=0;j<a.length();j++){
if(a[j]==b[j+i]){
count++;
}
}
if(count>maxcounta){
maxcounta=count;
diffa=i;
}
// }
// for(int i=0;i<diff;i++){
// a = "-" + a;
// }
}
if(maxcountb>maxcounta){
for(int i=0;i<diffb;i++){
b = "-" + b;
}
cout << a << endl << b << endl << maxcountb;
}
else{
for(int i=0;i<diffa;i++){
a = "-" + a;
}
cout << a << endl << b << endl << maxcounta;
}
/*
if(alen>=blen) calcstr(a,b);
else calcstr(b,a);
*/
return 0;
}