NC200063. CET and miniskirt
描述
输入描述
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; }