Advertisement
roronoa

anagram caché

Apr 25th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. import java.math.*;
  4. class Solution {
  5.  
  6.     public static void main(String args[])
  7.     {
  8.         Scanner in = new Scanner(System.in);
  9.         String w = in.next();
  10.         int n = in.nextInt();
  11.         if (in.hasNextLine())
  12.         {
  13.             in.nextLine();
  14.         }
  15.         int sum=0;
  16.         for (int i = 0; i < n; i++)
  17.         {
  18.             String s = in.nextLine();
  19.             boolean ok = true;
  20.                 for(int j = 0; j < w.length(); j++)
  21.                 {
  22.                     if(countXInString(s, w.charAt(j)) < countXInString(w, w.charAt(j)) )
  23.                     {
  24.                         ok = false;
  25.                     }
  26.                 }
  27.                
  28.             if(ok)
  29.                 sum++;
  30.         }
  31.         System.out.println(sum);
  32.     }
  33.     public static int countXInString(String s, char x)
  34.     {
  35.         int res = 0;
  36.         for(int i = 0; i < s.length(); i++)
  37.         {
  38.             if(x <= 'Z')
  39.             {
  40.                 if(s.toUpperCase().charAt(i) == x)
  41.                     res++;
  42.             }
  43.             else
  44.             {
  45.                 if(s.toLowerCase().charAt(i) == x)
  46.                     res++;
  47.             }
  48.         }
  49.         return res;
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement