Questions and codes:
/* Copyright (c) 2014, School of Computer and Control engineering, Yantai University
* All rights reserved.
* File name: Test.cpp
*: Yu Junyu
* Completion date: December 29, 2014
* version number: v1.0
*
* Problem Description: Xiao Ming to x Cave Expedition, picked up a broken martial arts cheats (2000 Multiple pages. Of course it's forged).
he noticed that pages 10th and 11th of the book were on the same sheet, but pages 11th and 12th were not on the same sheet.
Xiao Ming just want to practise the skill of the book from page A to page B, and don't want to take the whole book. How many sheets of paper should he tear off at least.
* Input Description: There are multiple sets of test instances, enter the start page A and the end page B that Xiaoming wants to practice. (a<b)
* Program output: Output Xiao Ming to take away the paper, each line corresponding to an output result.
*/
#include <iostream>
using namespace std;
int main ()
{
int a,b,i,n=0;
cin>>a>>b;
for (i=a; i<=b; i++)
{
if (i%2==0)
n++;
}
if (a%2==0&&b%2!=0)
cout<<n<<endl;
else
cout<<n+1<<endl;
return 0;
}
Operation Result:
Learning experience:
Do not know why in the codeblocks run is correct, in the OJ is not correct. Baidu in the search, but do not understand.
#include <iostream>
using namespace std;
int main ()
{
int m,n,a;
while (cin>>n>>m)
{
a=m-n+2;
A=A/2;
if (n%2!=0&&m%2==0)
a++;
cout<<a<<endl;
}
return 0;
}