Advertisement
roronoa

fruits juice

Apr 25th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.34 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. import java.math.*;
  4.  
  5.  
  6. class Solution {
  7. static class Fruit
  8. {
  9.     String name;
  10.     int need;
  11.     public Fruit(String name, int need)
  12.     {
  13.         this.name = name;
  14.         this.need = need;
  15.     }
  16.     public String toString()
  17.     {
  18.         return String.format("nom :  %s%n need : %s%n", name,need);  
  19.     }
  20. }
  21.  
  22.     public static void main(String args[])
  23.     {
  24.         Scanner in = new Scanner(System.in);
  25.         int N = in.nextInt();
  26.         if (in.hasNextLine())
  27.         {
  28.             in.nextLine();
  29.         }
  30.         Fruit fruits[] = new Fruit[N];
  31.         for (int i = 0; i < N; i++)
  32.         {
  33.             String s = in.nextLine();
  34.            
  35.             fruits[i] = new Fruit(s.split(" ")[0], Integer.parseInt(s.split(" ")[1]));
  36.         }
  37.         String LINE = in.nextLine();
  38.         int sum = 0;
  39.         for(int i=0; i < fruits.length; i++)
  40.         {
  41.             int nombre = countXInString(LINE, fruits[i].name);
  42.             sum = sum + nombre/fruits[i].need;
  43.         }
  44.        
  45.         System.out.println(sum);
  46.     }
  47.     public static int countXInString(String s, String x)
  48.     {
  49.         int res = 0;
  50.         for(int i = 0; i < s.length(); i++)
  51.         {
  52.             if(s.charAt(i) == x.charAt(0))
  53.                 res++;
  54.         }
  55.         return res;
  56.     }
  57.    
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement