Fortunately the child knows how to solve such complicated test. The child will follow the algorithm:
·If there is some choice whose description at least twice shorter than all other descriptions, or at least twice longer than all other descriptions, then the child thinks the choice is great.
·If there is exactly one great choice then the child chooses it. Otherwise the child chooses C (the child think it is the luckiest choice).
You are given a multiple-choice questions, can you predict child’s choose?
Input
The first line starts with “A.” (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix “X.”, so the prefix mustn’t be counted in description’s length.
Each description is non-empty and consists of at most 100 characters. Each character can be either uppercase English letter or lowercase English letter, or “_”.
Output
Print a single line with the child’s choice: “A”, “B”, “C” or “D” (without quotes).
Examples
input
A.VFleaKing_is_the_author_of_this_problem
B.Picks_is_the_author_of_this_problem
C.Picking_is_the_author_of_this_problem
D.Ftiasch_is_cute
output
D
input
A.ab
B.abcde
C.ab
D.abc
output
C
input
A.c
B.cc
C.c
D.c
output
B
Note
In the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices’, so it is great choice. There is no other great choices so the child will choose D.
In the second sample, no choice is great, so the child will choose the luckiest choice C.
In the third sample, the choice B (length 2) is twice longer than all other choices’, so it is great choice. There is no other great choices so the child will choose B.
思路:
如果有选项的长度
1.小于等于其他选项的一般
2.大于等于其他选项的两倍
满足其中一种条件则输出该选项,如果两个条件都满足或都不满足则输出C
AC代码:
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
pair<string,int> p[5];
bool cmp(pair<string,int> a,pair<string,int> b) {
return a.first.length()<b.first.length();
}
bool flag = false;
char ans;
int main() {
for(int i=0; i<4; i++) {
cin>>p[i].first;
p[i].second=i;
}
sort(p,p+4,cmp);
if((p[0].first.length()-2)*2<=p[1].first.length()-2) {
flag = !flag;
ans = p[0].second+'A';
}
if((p[2].first.length()-2)*2<=p[3].first.length()-2) {
flag = !flag;
ans = p[3].second+'A';
}
cout<<(flag ? ans : 'C')<<endl;
}
本文介绍了一种智能算法,用于帮助儿童解决作业中出现的多项选择题。算法通过比较选项描述的长度来判断正确答案,优先选择描述长度明显短于或长于其他选项的项,若无明显区别,则默认选择C。此方法基于儿童的直觉和幸运选择,为解决复杂测试提供了一种简单而有趣的方法。
1259

被折叠的 条评论
为什么被折叠?



