超有意思的小学编程题

由于小学生所拥有的计算方法有限

(他不会用函数,数组,循环,判断等一系列复杂语法结构)

Problem E: 武功秘籍

Time Limit: 1 Sec  Memory Limit: 128 MB

Description

小明到X山洞探险,捡到一本有破损的武功秘籍(2000多页!当然是伪造的)。
他注意到:书的第10页和第11页在同一张纸上,但第11页和第12页不在同一张纸上 。
小明只想练习该书的第a页到第b页的武功,又不想带着整本书。请问他至少要撕下多少张纸带走? 

Input

有多组测试实例,输入小明想要练习的起始页a和末尾页b。(a<b)

Output

输出小明最少要带走的纸张,每行对应一个输出结果。

Sample Input

81 92

Sample Output

7

有一个小学生做出来了:
 1 #include <iostream>
 2 #include <stdio.h>
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     int a,b;
 8     while(scanf("%d%d",&a,&b)!=EOF)
 9     {
10         //int c=a%2+(b-a+b%2)/2+(b+1)%2;
11         int c=(a%2+b-a+(b+1)%2+1)/2;
12         printf("%d
",c);
13     }
14     return 0;
15 }
View Code

还有一个同学也做出来了,只是他取模运算也不会,却也做出来了

 1 #include <iostream>
 2 #include <stdio.h>
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     int a,b;
 8     while(scanf("%d%d",&a,&b)!=EOF)
 9     {
10         int c=b/2-a/2+1;
11         printf("%d
",c);
12     }
13     return 0;
14 }
View Code

聪明得小学同学们,你们有什么更好的方法吗?

原文地址:https://www.cnblogs.com/vivider/p/3645782.html