-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05_String_22.cpp
More file actions
69 lines (69 loc) · 1.57 KB
/
Copy path05_String_22.cpp
File metadata and controls
69 lines (69 loc) · 1.57 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
#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(),maxcount=0,maxdiff=0,diff=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>maxcount){
maxcount=count;
diff=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>maxcount){
maxcount=count;
diff=i;
}
}
for(int i=0;i<diff;i++){
a = "-" + a;
}
}
cout << a << endl << b << endl << maxcount;
/*
if(alen>=blen) calcstr(a,b);
else calcstr(b,a);
*/
return 0;
}