最省納智捷1年新車83萬起工程師靠存股年領百萬股息輕忽小中風,當心變殘障睽違25天終開會 立院...
2013-05-29 16:29:08 人氣(345) | 回應(0) | 推薦(0) | 收藏(0) 上一篇 | 下一篇

[UVA][Easy] 12626 - I ❤ Pizza

0
收藏
0
推薦

 G - I ❤ Pizza 

Context

Everybody loves pizza: Margarita, Four cheese, Salami, Caprichosa, Neapolitan, Hawaiian... The famous pizza Margarita is named after the Italian Queen Margarita of Savoy. It is said that the chef Raffaele Esposito gave her to choose from a variety of pizzas he had prepared specially for the Queen. Margarita chose this pizza in honor of the colors of the Italian flag: red tomato, white cheese, and green basil.

Una rica pizza

However, some people argue that, in fact, Queen Margarita did not like onion, and as all the other pizzas had onion, she had no choice but that pizza.

The Problem

In our particular computerized kitchen, ingredients are named by capital letters: A, B, C, D... Thus, to make a pizza MARGARITA we need as many ingredients as their letters, i.e. one M, three A, two R, one G, one I, and one T.

For example, if we have the ingredients:

AAAAAAMMRRTITIGGRRRRRRRR

Then we can make 2 pizzas MARGARITA, and still spare some R.

Given a set of ingredients, you have to say how many pizzas MARGARITA can be made. Note that there may be leftover ingredients, and also there may be unnecessary ingredients, such as B.

The Input

The first line contains a natural number, N, which indicates the number of test cases.

Each test case is given in one line. This line contains a series of capital letters from A to Z, which can be messy and may be repeated. At most one line can have 600 characters.

The Output

For each test case, you must indicate how many pizzas MARGARITA can be made with the letters available, taking into account that there may be spare letters.

Sample Input

5
MARGARITA
AAAAAAMMRRTITIGGRRRRRRRR
AMARGITA
BOLOGNESACAPRICHOSATOMATERA
ABCDEFGHIJKLMNOPQRSTUVWXYZ

Sample Output

1
2
0
1
0


OMP'13
Facultad de Informática
Universidad de Murcia

給定材料要求製作一單位的 pizza, 給所有材料的量, 問最多能製作多少片 pizza

#include <stdio.h>
#include <algorithm>
using namespace std;
int main() {
    int t;
    char s[605];
    scanf("%d", &t);
    while(t--) {
        scanf("%s", s);
        int ascii[128] = {};
        for(int i = 0; s[i]; i++)
            ascii[s[i]]++;
        int ret = 0xffff;
        ret = min(ret, ascii['M']/1);
        ret = min(ret, ascii['A']/3);
        ret = min(ret, ascii['R']/2);
        ret = min(ret, ascii['G']/1);
        ret = min(ret, ascii['T']/1);
        ret = min(ret, ascii['I']/1);
        printf("%d\n", ret);
    }
    return 0;
}

12626I ❤ Pizza
台長:Morris
人氣(345) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][Easy] 12614 - Earn For Future
此分類上一篇:[UVA][Easy] 12611 - Beautiful Flag

我要回應
是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入以下數字 (ex:123)

(有*為必填)
詳全文