2019牛客暑期多校训练营(第六场)A Garbage Classification

链接:https://ac.nowcoder.com/acm/contest/886/A

problem

On the CVBB planet, garbage classification has been gradually executed to help save resources and protect the environment. Nowadays people have to be equipped with knowledge of distinguishing different types of garbage. Now, given the waste compositions of a discarded product, you are asked to determine which category it belongs to.

The waste compositions are represented as a string s consisting of only lowercase letters, where each letter represents a waste composition and has an equal proportion. Each waste composition in that product is in one of the three situations, dry, wet or harmful.

The product can be classified by the following rules:

In case that at least 25% of its compositions is harmful, it is harmful garbage.
In case that at most 10% of its compositions is harmful, it is recyclable garbage.
In other cases, if the proportion of dry compositions in it is at least twice that of wet compositions, it is dry garbage, or otherwise, it is wet garbage.

输入描述:

There are multiple test cases. The first line contains an integer T (1 \leq T \leq 501≤T≤50), indicating the number of test cases. Test cases are given in the following.

For each test case, the first line contains a non-empty string s (1 \le |s| \le 20001≤∣s∣≤2000) consisting of only lowercase letters.

The second line contains a string t of length 26, consisting of only characters in \lbrace d, w, h \rbrace{d,w,h}. The i-th character of t represents the situation of the waste composition denoted by the i-th lowercase letter, where ‘d’, ‘w’ and ‘h’ mean dry, wet or harmful respectively.

输出描述:

For each test case, output “Case #x: y” in one line (without quotes), where x indicates the case number starting from 1, and y (y \in \lbrace \text{Harmful}, \text{Recyclable}, \text{Dry}, \text{Wet} \rbracey∈{Harmful,Recyclable,Dry,Wet}) denotes the garbage type of the product in this test case.

示例

输入

4
dqxxjefgctjgdbqxphff
hddhddhhhdhdhwwddhhdwwdhhw
iqdvfzzdqsbdevzebego
wdhddwwhwhdhhhwwdwdhwdwhhd
erkjqzsmchcmbqeasadf
dwddddwdwdwhdwhhdhhwwhhwdh
mcxkwmxxlhbrymwawhio
ddhwhddhwwwdddwdwhwwwhdwdw

输出

Case #1: Harmful
Case #2: Recyclable
Case #3: Dry
Case #4: Wet

题意

输入的样例中,第一行给出了由小写字母组成的字符串,第二行给出了每个小写字母所代表的垃圾属性(有害,湿,干),根据第二行对第一行的字符串进行判断
如果其中至少25%的成分是有害的,那就是有害垃圾。
如果它的成分中有10%以上是有害的,那么它就是可回收垃圾。
在其他情况下,如果干成分的比例至少是湿成分的两倍,则为干垃圾,否则为湿垃圾。

分析

将要判断的字符串里面的三种属性分别计算出来,再最终进行计算是哪一种垃圾

代码

#include<bits/stdc++.h>
using namespace std; 
char s[2004],z[30];

int main(){
    int t;
    cin>>t;
    for(int k=1; k<t+1; k++) {
        scanf("%s%s",&s,&z);
        double x=strlen(s);
        double d=0,w=0,h=0;
        for(int i=0;i<x;i++)
		{
            int a=s[i]-'a';
            if(z[a]=='d')d++;  
            else if(z[a]=='w')w++;
            else if(z[a]=='h')h++;
        }
        if(h/x>=0.25)printf("Case #%d: Harmful\n",k);
        else if(h/x<=0.1) printf("Case #%d: Recyclable\n",k);
        else if(d>=w*2)printf("Case #%d: Dry\n",k);
        else printf("Case #%d: Wet\n",k);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值