Codeforces Round #250 (Div. 2) 437A The Child and Homework(模拟)
来源:互联网 发布:小学英语课堂软件 编辑:程序博客网 时间:2024/05/29 11:06
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.
好好读题轻易ac,题目说有确定的一个选项则输出该选项,否则输出C。
AC代码:
#include "iostream"#include "cstdio"#include "cstring"#include "algorithm"using namespace std;struct node{/* data */int len;char s[200], flag;}a[4];bool cmp(node a, node b){if(a.len == b.len)return a.flag < b.flag;return a.len < b.len;}int main(int argc, char const *argv[]){for(int i = 0; i < 4; ++i) {scanf("%s", a[i].s);a[i].flag = a[i].s[0];a[i].len = strlen(a[i].s) - 2;}sort(a, a + 4, cmp);bool flag1 = false, flag2 = false;if(a[0].len * 2 <= a[1].len) flag1 = true;if(a[3].len >= a[2].len * 2) flag2 = true;if((flag2 && flag1) || (!flag2 && !flag1)) printf("C\n"); else if(flag1) printf("%c\n", a[0].flag);else if(flag2) printf("%c\n", a[3].flag);return 0;}
- Codeforces Round #250 (Div. 2) 437A 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 Round #250 (Div. 2)—A. The Child and Homework
- Codeforces #250 (Div. 2) A. The Child and Homework
- 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
- #250 div.2 A. The Child and Homework
- Codeforces Round #250 (Div. 1) A. The Child and Toy
- Codeforces Round #250 Div. 2(C.The Child and Toy)
- Codeforces Round #250 (Div. 2) -B. The Child and Set
- Codeforces Round #250 (Div. 2) -C. The Child and Toy
- Codeforces 437A The Child and Homework(水题)
- Codeforces Round #250 (Div. 2) 437C The Child and Toy(脑洞贪心)
- Codeforces Round #250 (Div. 1) D. The Child and Sequence
- Codeforces Round #250 (Div. 1) D. The Child and Sequence
- Linux编程基础
- hdu4770 状态压缩+枚举
- 写一篇文章纪念一下儿子入学
- HDU3722 Card Game(KM最小费用圈覆盖)
- GO1.5标准包http.FileServer的拔高用法.
- Codeforces Round #250 (Div. 2) 437A The Child and Homework(模拟)
- 给自己的总结
- epoll模型详解 2010-10-09 17:39:38 http://blog.chinaunix.net/uid-20583479-id-1920065.html
- LeetCode(47)Permutations II
- JDK与JRE的区别
- java中的volatile关键字
- C语言---算法(选择排序/冒泡排序/折半查找/进制查表法)
- Spring整合JMS(三)——MessageConverter介绍
- hdu 4902 Nice boat(线段树区间更新lazytag·单点更新)