Codeforces Round #250 (Div. 2) A. The Child and Homework

时间:2023-03-08 23:04:46
Codeforces Round #250 (Div. 2)  A. The Child and Homework

注意题目长度不能考虑前缀,而且如果即存在一个选项的长度的两倍小于其他所有选项的长度,也存在一个选项的长度大于其他选项长度的两倍,则答案不是一个好的选择,只能选择C。

#include <iostream>
#include <vector>
#include <string>
#include <algorithm> using namespace std; struct Answer{
char item;
int length;
Answer(char item_ = 'A', int length_ = ):item(item_),length(length_){}
bool operator<(const Answer& a) const{
return length < a.length;
}
}; int main(){
vector<Answer> ans;
for(int i = ; i < ; ++ i){
string str;
cin >> str;
ans.push_back(Answer(str[],str.length()-));
}
sort(ans.begin(),ans.end());
int index = ;
char correct = 'C';
for(index = ;index < ; ++ index){
if(ans[index].length < *ans[].length) break;
}
if(index>=) correct = ans[].item;
for(index = ; index < ; ++ index){
if(*ans[index].length >ans[].length) break;
}
if(index >= ) {
if(correct!='C') correct = 'C';
else correct = ans[].item;
}
cout<<correct<<endl; }