题意:给出一串字符和每个字母代表的意义,进行分类判断字符串是什么类型
思路:直接计数然后乘100求出百分比,然后根据题意输出就行了
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<n;i++)
#define per(i, n) for(int i=n;i>=1;i--)
#define pb(x) push_back(x)
using namespace std;
typedef long long ll;
const int maxn = 1e5;
const ll inf =INT64_MAX;
using namespace std;
#include<bits/stdc++.h>
using namespace std;
int n,t;
char str[5000];
char jud[30];
ll num[10];
int main(){
scanf("%d",&t);
getchar();
int d,w,h,cnt=0;
while(t--){
cnt++;
scanf("%s",str);
getchar();
scanf("%s",jud);
d=w=h=0;
int len=strlen(str);
rep(i,len){
if(jud[str[i]-'a']=='d') d++;
else if(jud[str[i]-'a']=='w') w++;
else h++;
}
double hh=h*100.0/len;
bool b;
if(d>=2*w) b= true;
else b= false;
if(hh>=25.0) printf("Case #%d: Harmful\n",cnt);
else if(hh<=10.0) printf("Case #%d: Recyclable\n",cnt);
else{
if(b) printf("Case #%d: Dry\n",cnt);
else printf("Case #%d: Wet\n",cnt);
}
}
return 0;
} 
京公网安备 11010502036488号