Codechef Program#43 :Chef and String
![]() |
Chef and String |
Chef and String
Read problems statements in Russian also.
Chef likes playing with strings. The most interesting game are named "CHEF in string". The move of the game consists of the following: Chef takes a subsequence of string's letters that form the word "CHEF" and then he removes that symbols. The goal of the game is to make the maximal number of moves. Please, help Chef and tell him the maximal possible number of moves that he is able to make for the given string S.
Input
The first line of each test case contains a given string. This string consists of uppercase letters from the set {"C", "H", "E", "F"}.
Output
Output a single line containing the maximal possible number of moves.
Constraints
- 1 ≤ |S| ≤ 100000
Example
Input: CHEFCHEFFFF Output: 2
Input: CHHHEEEFFCC Output: 1
My Solution:
import java.io.*; import java.util.*; /* Name of the class has to be "Main" only if the class is public. */ class horses { public static void main (String[] args) throws java.lang.Exception { Scanner br=new Scanner(System.in); int t=br.nextInt(); while(t-->0) { int m=1000000001; int n=br.nextInt(); int arr[]=new int[n]; for (int i=0;i<arr.length;i++) arr[i]=br.nextInt(); Arrays.sort(arr); for(int i=0;i<arr.length-1;i++) { if(arr[i+1]-arr[i]<m) { m=arr[i+1]-arr[i]; } } System.out.println(m); } } }
posted by lol ik
Comments
Post a Comment