Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- import java.math.*;
- class Solution {
- static class Fruit
- {
- String name;
- int need;
- public Fruit(String name, int need)
- {
- this.name = name;
- this.need = need;
- }
- public String toString()
- {
- return String.format("nom : %s%n need : %s%n", name,need);
- }
- }
- public static void main(String args[])
- {
- Scanner in = new Scanner(System.in);
- int N = in.nextInt();
- if (in.hasNextLine())
- {
- in.nextLine();
- }
- Fruit fruits[] = new Fruit[N];
- for (int i = 0; i < N; i++)
- {
- String s = in.nextLine();
- fruits[i] = new Fruit(s.split(" ")[0], Integer.parseInt(s.split(" ")[1]));
- }
- String LINE = in.nextLine();
- int sum = 0;
- for(int i=0; i < fruits.length; i++)
- {
- int nombre = countXInString(LINE, fruits[i].name);
- sum = sum + nombre/fruits[i].need;
- }
- System.out.println(sum);
- }
- public static int countXInString(String s, String x)
- {
- int res = 0;
- for(int i = 0; i < s.length(); i++)
- {
- if(s.charAt(i) == x.charAt(0))
- res++;
- }
- return res;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement