Codeforces Round #250 (Div. 2) 437A The Child and Homework(模拟)
2015-08-31 20:19
429 查看
A. The Child and Homework
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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?
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).
Sample test(s)
input
output
input
output
input
output
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.
好好读题轻易ac,题目说有确定的一个选项则输出该选项,否则输出C。
AC代码:
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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?
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).
Sample test(s)
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.
好好读题轻易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; }
相关文章推荐
- HLG2179 组合(dfs水水更健康)
- 通过一个date获取年龄
- ios MVC笔记
- gulp
- 利用Hexo搭建个人博客-环境搭建篇
- JDK与JRE的区别
- 海量数据处理一
- HDU1495-非常可乐-BFS
- UITextFielddelegate委托方法注释
- hdu4770 状态压缩+枚举
- LeetCode(47)Permutations II
- Java技术积累——用最原始的代码见证分页查询实现原理
- hust1350Trie【字典树+dfs || 字典树 + LCA】
- LeetCode(47)Permutations II
- Linux编程基础
- Servlet中用于会话跟踪的三种机制
- HDU3722 Card Game(KM最小费用圈覆盖)
- 黄聪:WordPress动作钩子函数add_action()、do_action()源码解析
- linux 文件系统解析及相关命令
- 计算1到100的整数和