A ceremony where a Bride chooses her Groom from an array of eligible bachelors is called Swayamvar. But this is a Swayamvar with difference. An array of Bride-to-be will choose from an array of Groom-to-be.
Answers
Answer:
package Arrays;
import java.util.*;
public class Swayamvar {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
String BrideChoice = scn.next();
String GhroomChoice = scn.next();
int brLen = n;
for(int i = 0; i < n; i++) {
boolean condition = false;
int loop = brLen;
for(int j = 0; j < loop; j++) {
//removing character from string
if(BrideChoice.charAt(0) == GhroomChoice.charAt(j)) {
BrideChoice = charRemoveAt(BrideChoice, 0);
GhroomChoice = charRemoveAt(GhroomChoice, j);
brLen -= 1;
condition = true;
break;
}
}
if(condition == false) {
break;
}
}
System.out.println(brLen);
}
public static String charRemoveAt(String str, int p) {
// System.out.println(str.substring(0, p) + str.substring(p + 1));
return str.substring(0, p) + str.substring(p + 1);
}
}
Explanation: