Nine degrees oj-topic 1063: Integers and

Source: Internet
Author: User

Title Description:

Write a program that reads an integer n.
If n is a non-negative number, the integer between N and 2N is computed;
If n is a negative number, the integer between 2N and n is calculated and

Input:

The absolute value of an integer n,n is less than or equal to 1000

Output:

The test data may have multiple groups, for each set of data,
Output the value of the title requirement

Sample input:
1-1
Sample output:
3-3
Source:
2001, Tsinghua University, computer research, real life test (I set)
Answering:
problem solving problems? to discuss the subject of discussion please visit: http://t.jobdu.com/thread-7787-1-1.html

#include <iostream>using namespace Std;int main () {    int n,count,i;    while (Cin>>n)    {      count=0;      if (n>=0) {for        (i=n;i<=n*2;i++) {           count+=i;        }      }      else if (n<0) {for        (i=n*2;i<=n;i++) {           count+=i;        }      }      cout<<count<<endl;    }    return 0;} /**************************************************************    problem:1063    user:vhreal    language:c++    result:accepted    time:30 ms    memory:1520 kb******************************************* *********************/


Nine degrees oj-topic 1063: Integers and

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.