The skill cheats of OJ brush problem

Source: Internet
Author: User
Tags ming

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;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.