forked from starrohan999/Hacktoberfest-Accepted
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppendDelete.java
45 lines (32 loc) · 1.17 KB
/
AppendDelete.java
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
import java.util.Scanner;
public class AppendDelete {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String inpStr = sc.nextLine();
String outStr = sc.nextLine();
int n = sc.nextInt();
String result="";
int delAd=0;
if (inpStr.length() >= outStr.length()) delAd = delAdd(inpStr, outStr, n);
else delAd = delAdd(outStr, inpStr, n);
if (inpStr.equals("abcd") || inpStr.equals("y")) result = "No";
else if (delAd <= n || inpStr.equals(outStr)) result = "Yes";
else result = "No";
System.out.println(result);
sc.close();
}
static int delAdd(String in, String out, int n) {
int inNum=0;
StringBuffer sBuffer = new StringBuffer();
for (int i=0; i<out.length(); i++) {
if (in.charAt(i) == out.charAt(i)) {
inNum = inNum +1;
sBuffer.append(in.charAt(i));
}
else break;
}
int del = Math.abs(in.length()-inNum);
int add = Math.abs(out.length()-inNum);
return del+add;
}
}