zoukankan      html  css  js  c++  java
  • Codeforces Gym101502 E.The Architect Omar-find()函数

    E. The Architect Omar
     
    time limit per test
    1.0 s
    memory limit per test
    256 MB
    input
    standard input
    output
    standard output

    Architect Omar is responsible for furnishing the new apartments after completion of its construction. Omar has a set of living room furniture, a set of kitchen furniture, and a set of bedroom furniture, from different manufacturers.

    In order to furnish an apartment, Omar needs a living room furniture, a kitchen furniture, and two bedroom furniture, regardless the manufacturer company.

    You are given a list of furniture Omar owns, your task is to find the maximum number of apartments that can be furnished by Omar.

    Input

    The first line contains an integer T (1 ≤ T ≤ 100), where T is the number of test cases.

    The first line of each test case contains an integer n (1 ≤ n ≤ 1000), where n is the number of available furniture from all types. Then nlines follow, each line contains a string s representing the name of a furniture.

    Each string s begins with the furniture's type, then followed by the manufacturer's name. The furniture's type can be:

    • bed, which means that the furniture's type is bedroom.
    • kitchen, which means that the furniture's type is kitchen.
    • living, which means that the furniture's type is living room.

    All strings are non-empty consisting of lowercase and uppercase English letters, and digits. The length of each of these strings does not exceed 50 characters.

    Output

    For each test case, print a single integer that represents the maximum number of apartments that can be furnished by Omar

    Example
    input
    1
    6
    bedXs
    kitchenSS1
    kitchen2
    bedXs
    living12
    livingh
    output
    1

     这个题水题,用find()写。

    代码:

     1 //E. The Architect Omar-find函数
     2 #include<iostream>
     3 #include<cstring>
     4 #include<cstdio>
     5 #include<queue>
     6 #include<algorithm>
     7 #include<cmath>
     8 using namespace std;
     9 int main(){
    10     int t,n;
    11     scanf("%d",&t);
    12     while(t--){
    13         scanf("%d",&n);
    14         int num1=0,num2=0,num3=0;
    15         for(int i=0;i<n;i++){
    16             string s;
    17             cin>>s;
    18             if(s.find("bed")==0)num1++;
    19             if(s.find("kitchen")==0)num2++;
    20             if(s.find("living")==0)num3++;
    21         }
    22         //cout<<num1<<" "<<num2<<" "<<num3<<endl;
    23         int ans=min(num1/2,min(num2,num3));
    24         printf("%d
    ",ans);
    25     }
    26     return 0;
    27 }
  • 相关阅读:
    【kd-tree】bzoj2648 SJY摆棋子
    【kd-tree】bzoj3053 The Closest M Points
    【堆】【kd-tree】bzoj2626 JZPFAR
    【kd-tree】bzoj1941 [Sdoi2010]Hide and Seek
    【kd-tree】bzoj2850 巧克力王国
    【kd-tree】bzoj3489 A simple rmq problem
    【kd-tree】bzoj4066 简单题
    【二维莫队】【二维分块】bzoj2639 矩形计算
    【kd-tree】bzoj1176 [Balkan2007]Mokia
    【kd-tree】bzoj3290 Theresa与数据结构
  • 原文地址:https://www.cnblogs.com/ZERO-/p/9703289.html
Copyright © 2011-2022 走看看