CodeForces 437 A. The Child and Homework
来源:互联网 发布:淘宝seo的优化流程 编辑:程序博客网 时间:2024/05/16 11:14
纯属练习JAVA....
Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct.
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?
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 "_".
Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes).
A.VFleaKing_is_the_author_of_this_problemB.Picks_is_the_author_of_this_problemC.Picking_is_the_author_of_this_problemD.Ftiasch_is_cute
D
A.abB.abcdeC.abD.abc
C
A.cB.ccC.cD.c
B
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.
import java.util.*;public class Main{public static void main(String[] args){Scanner cin=new Scanner(System.in);String[] xuan=new String[4];for(int i=0;i<4;i++)xuan[i]=cin.nextLine();StringBuilder ans=new StringBuilder();for(int i=0;i<4;i++){int goal=xuan[i].length()-2;int flag1=0,flag2=0;for(int j=0;j<4;j++){if(i==j) continue;int temp=xuan[j].length()-2;if(goal*2<=temp)flag1++;if(temp*2<=goal)flag2++;}if(flag1==3||flag2==3)ans.append((char)(i+'A'));}if(ans.length()==1)System.out.println(ans);elseSystem.out.println("C");}}
- Codeforces 437A The Child and Homework
- CodeForces 437 A. The Child and Homework
- Codeforces 437A The Child and Homework
- Codeforces 437A The Child and Homework
- Codeforces 437A The Child and Homework(水题)
- A. The Child and Homework
- Codeforces Round #250 (Div. 2) A. The Child and Homework
- Codeforces Round #250 (Div. 2) A - The Child and Homework
- Codeforces #250 (Div. 2) A. The Child and Homework
- Codeforces Round #250 (Div. 2) 437A The Child and Homework(模拟)
- Codeforces Round #250 (Div. 2)—A. The Child and Homework
- cf437A The Child and Homework
- #250 div.2 A. The Child and Homework
- CF #250 The Child and Homework
- Codeforces 437B The Child and Set
- codeforces 437C The Child and Toy
- codeforces 437D The Child and Zoo
- CodeForces 437C The Child and Toy
- Android Training - Volley(Lesson 0 - 序言)
- 构造函数限定符的使用
- Android Training - Volley(Lesson 1 - 发送简单的请求)
- iOS7.0后 根据字符串长度计算label的尺寸
- KMP
- CodeForces 437 A. The Child and Homework
- make[1]: *** [libgd.la] Error 1解决方法
- hdu-1242-Rescue-优先队列
- Java Persistence with MyBatis 3(中文版) 第二章 引导MyBatis
- Uiautomator 新体验
- Windows Phone 8.1 App 图片资源需求列表
- 安卓自带示例BluetoothChat详解
- configure error:安装php时出现configure: error: Unable to find gd.h anywhere under,错误解决
- C 字符串危险操作函数和替换方法