-
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