-1
votes

Trouvez des soustractions de la première chaîne dans la deuxième chaîne?

MISE À JOUR: J'ai deux chaînes.

  String a = "is am are has have was " //Helping verbs
  String b= " Robert and william are English Robert has a car he was living in England " //Sentence


0 commentaires

4 Réponses :


0
votes
 String a = "one two three four five six ";
    String b= " eleven two four twelve thirteen "  ;
           List<String> aSub =   Arrays.asList(a.split(" "));
           List<String> bSub =   Arrays.asList(b.split(" "));

    for(String s1 :aSub){
        for(String s2 :bSub){
            if(s1.equalsIgnoreCase(s2)){
            System.out.println( s1+" exists and is found in index "+ bSub.indexOf(s1));
        }
      }
    }

result:
two exists and is found in index 2
four exists and is found in index 3

1 commentaires

Existe: Existe et se trouve dans l'Index 3 existe et se trouve dans l'Index 6 existait et se trouve dans l'index 10 Bread 10 Bread Brew (Temps total: 4 secondes)



0
votes

Un moyen facile de diviser la chaîne serait d'utiliser la classe StringTokenizerzer xxx


0 commentaires

0
votes
//Big O of N*N solution
class SubString{
public static void main(String [] args)
{
System.out.println(new SubString().getCommonSubString("abcdefg","zycdemm"));
}
public int getCommonSubString(String A, String B)
{
int ans =0;

     for(int i=0;i<A.length();i++)
     {
       int c=0;
       int k =i;
       for(int j=0;k<A.length()&&j<B.length();j++)
       {

         if(A.charAt(k)==B.charAt(j))
         {
           c++;
           ans = Math.max(ans, c);
           k++;
         }else
         {
           c=0;
           k=i;
         }
      }
    }
 return ans;
}
}

1 commentaires

Ce code résultat: Exception dans le fil "Main" Java.lang.stringindexoutofboundsException: Indice de chaîne hors de portée: 23 à java.base / java.lang.stringlatin1.charat (StringLatin1.java:48) à Java.Base / Java. lang.string.chardat (string.java:709)



4
votes

Veuillez trouver le code ci-dessous: - xxx

sortie: -

{1 = 1, 3 = 2}


7 commentaires

FindHelpingverbs (String [] A, String [] B) {Carte MapMatchingStrings = Nouveau hachmap <> (); IntStream .Range (0, A.Length) .foreseach (indexofstringone -> intestream .Range (0, b.length) .foreseach (indexofstringtwo -> {si (Objets de si (IndexoStringone], B [IndexOpstringTwo]))) {MAPMATCHINGINGSTRINGSSTRESSTRINGS (indexofstringone, indexofstringtwo);}})); System.out.println (MapMatchingStrings); } Résultat: {} // blanc, aucun résultat


Envoyez-vous la même entrée que vous avez fait dans la question?


S'il y a une autre entrée, veuillez me l'envoyer.


Oui, le résultat que vous obtenez par votre code est {2 = 3, 3 = 6, 5 = 10}


Est-ce la réponse que vous vouliez?


Run: {2 = 3, 3 = 6, 5 = 10} Construire réussi (temps total: 0 secondes)


Ce sont tous des correspondances à la fois. Je veux ce processus un par un. Lorsque la première sous-chaîne de "String A" est trouvée dans "String B", obtenez la sous-chaîne précédente si elle est trouvée (exception: index 0 sous-chaîne) et ensuite sous la sous-chaîne et faites des relations dans n'importe quelle source de données comme AST. Si les doublons ont constaté qu'ils se fusionneront dans la sous-chaîne existante.