Golden Khon Kaen
InterviewTime limit10sMemory limit64 MB
Count how many times the word GOLDEN can be formed from each given string of capital letters.
- Level
Easy1 of 10
- Topics
- Hash map
- Solved
- No attempts yet
Problem
Khon Kaen is a province in northeastern Thailand. Its slogan is
พระธาตุขามแก่น เสียงแคนดอกคูน ศูนย์รวมผ้าไหม ร่วมใจผูกเสี่ยว
เที่ยวขอนแก่นนครใหญ่ ไดโนเสาร์สิรินธรเน่ สุดเท่เหรียญทองมวยโอลิมปิก
The slogan names two golden things. The first is the golden shower, ดอกคูน, the official flower of the province. The second is the gold medal, Thailand's first Olympic gold, won by Somruk Khamsing, whose hometown is Khon Kaen.
To celebrate the golden province, count how many copies of the word GOLDEN a given series of letters can form. All letters are capitals from A to Z. One GOLDEN needs exactly one G, one O, one L, one D, one E and one N.
For example, from the series GOOOOOOOOLDENN you can build one GOLDEN, and some O and N are left over.
Given several series of letters, report for each one the largest number of GOLDEN words it can form. Letters may be left over, and letters that are not needed at all, such as B, may appear.
Input
The first line contains the number of test cases (). Each of the next lines contains one test case: a series of capital letters from A to Z, in any order and with repetitions allowed. A line is at most 400 characters long.
Output
For each test case, print on its own line the largest number of GOLDEN words that the available letters can form. Leftover letters are allowed.