列表

详情


NC200063. CET and miniskirt

描述

Xuxu is a student who likes English and skirt.Therefore, he has spent a lot of time preparing for CET. CET is a very important test, which determines the style of Xuxu's skirt this year. 
Xuxu just finished the CET and got the standard answer after that. What's more , if Xuxu gets zero, he will wear a skirt to the party, otherwise he will wear a suit(which is very disappointing). So Xuxu wants to know if it is possible for him to wear a skirt to the party. But unfortunately, he only remembers how many A, B, C and D he has written. Can you tell him weather he can wear a skirt in the party ?

输入描述

The first line contains an integer n which indicates the number of questions.
The second line contain a string s which indicates the answer of each question.The answer only contain the upper case letters 'A','B','C' and 'D'.
The third line contain four integer a,b,c,d indicates the number of A,B,C,D Xuxu has written.

输出描述

If it's impossible for Xuxu to wear skirt, output the minimum number of questions Xuxu may answer correctly, Otherwise output "orz"

示例1

输入:

4
ABCD
1 1 1 1

输出:

orz

说明:

It's possible to get a zero if Xuxu has written BADC in CET.

示例2

输入:

3
AAA
2 1 0 0

输出:

2

说明:

It's impossible to get a zero and the minium number of question Xuxu can answer correctly is 2.

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++14(g++5.4) 解法, 执行用时: 9ms, 内存消耗: 660K, 提交时间: 2020-01-11 18:38:38

#include <bits/stdc++.h>
using namespace std;
int a[4], b[4], n;
string s;
int main()
{
 	cin >> n >> s;
 	for(int i=0; i<4; i++) cin >> a[i];
 	for(int i=0; i<4; i++) b[i] = count(begin(s), end(s), 'A'+i);
 	for(int i=0; i<4; i++) if(b[i]-(n-a[i])>0) return cout << b[i]-(n-a[i]), 0;
	return cout << "orz", 0;
}

C++11(clang++ 3.9) 解法, 执行用时: 11ms, 内存消耗: 608K, 提交时间: 2020-02-25 13:55:06

#include<bits/stdc++.h>
using namespace std;
int n,a[4],b[4],ans;
char ch;
int main()
{
	cin>>n;
	for(int i=0;i<n;++i)
	{
		cin>>ch;
		a[ch-'A']++;
		
	}
	for(int i=0;i<4;++i)
	cin>>b[i];
	for(int i=0;i<4;++i)
	ans=max(ans,a[i]+b[i]-n);
	if(ans) cout<<ans;
	else cout<<"orz";
	return 0;
}

上一题