forked from keshavagarwal17/All-Cp-Algo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoneaway.java
69 lines (65 loc) · 1.14 KB
/
oneaway.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package development;
import java.util.*;
public class oneaway {
public static void replace(String a, String b) {
int count =0;
for(int i=0;i<a.length();i++)
{
if(a.charAt(i)!=b.charAt(i)) {
count++;
}
}
if(count>1) {
System.out.println("False");
}
else {
System.out.println("True");
}
}
public static void insert(String b, String a) {
int j=0;
int i=0;
int c=0;
while(i<b.length() && j<a.length())
{
if(a.charAt(j)!=b.charAt(i))
{
j++;
c++;
}
else {
i++;
j++;
}
}
if(c>1) {
System.out.println("False");
}
else {
System.out.println("True");
}
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String a = scan.next();
String b = scan.next();
System.out.println(a);
System.out.println(b);
if(a.length()==b.length())
{
replace(a,b);
}
else if (a.length()-1 == b.length())
{
insert(b,a);
}
else if(a.length() == (b.length()-1))
{
insert(a,b);
}
else {
System.out.println("False");
}
scan.close();
}
}