|
|
вернуться в форумAbout Sum Problem1068 Послано Saud 9 ноя 2011 21:42 Sir Kindly Tell me the why my this Problem's solution is not acceptable? #include<iostream> using namespace std; int main() { int num,n; int i; cin>>n; while(n>0) { cin>>num; if(num>10000) return 0; else if(num<0) { i = ((num*(num-1))/2)*(-1); cout<<i+1<<endl; } else cout<<(num*(num+1))/2<<endl; n--; } return 0; }
Re: About Sum Problem1068 You have to read/write a single number. Re: About Sum Problem1068 Послано Saud 9 ноя 2011 21:59 But Sir when i was taking a single input then at that time also not accept my solution. The error was "wrong answer Test#2". Kindly tell me what was wrong that time? Re: About Sum Problem1068 Well, obviously you have an incorrect formula Did you made a check on the paper with, let's say N = -1? The "i = ((num*(num-1))/2)*(-1); cout<<i+1<<endl;" formula is wrong also for the sample input, you will output 7. Re: About Sum Problem1068 Послано Saud 10 ноя 2011 14:44 No sir when i give input N=-1 the OutPut is 0. If this is Wrong then tell me plz what should be output when N=-1 Re: About Sum Problem1068 How about for N = 0? Re: About Sum Problem1068 Послано Saud 10 ноя 2011 16:56 Thank you very much sir. My solution was not able to generate required result when N = 0 Now after the correction in my Solution my solution is accepted. Again Thank you for help me. |
|
|