标签:style class blog code java http
注意题目长度不能考虑前缀,而且如果即存在一个选项的长度的两倍小于其他所有选项的长度,也存在一个选项的长度大于其他选项长度的两倍,则答案不是一个好的选择,只能选择C。
#include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; struct Answer{ char item; int length; Answer(char item_ = ‘A‘, int length_ = 0):item(item_),length(length_){} bool operator<(const Answer& a) const{ return length < a.length; } }; int main(){ vector<Answer> ans; for(int i = 0 ; i < 4; ++ i){ string str; cin >> str; ans.push_back(Answer(str[0],str.length()-2)); } sort(ans.begin(),ans.end()); int index = 1; char correct = ‘C‘; for(index = 1;index < 4; ++ index){ if(ans[index].length < 2*ans[0].length) break; } if(index>=4) correct = ans[0].item; for(index = 0; index < 3; ++ index){ if(2*ans[index].length >ans[3].length) break; } if(index >= 3) { if(correct!=‘C‘) correct = ‘C‘; else correct = ans[3].item; } cout<<correct<<endl; }
Codeforces Round #250 (Div. 2) A. The Child and Homework,布布扣,bubuko.com
Codeforces Round #250 (Div. 2) A. The Child and Homework
标签:style class blog code java http
原文地址:http://www.cnblogs.com/xiongqiangcs/p/3779653.html