1049 - Sum

Discussion around the problems of the COJ.
Forum rules
Remember that posting AC code is not allowed here. If you are going to ask a question or to post a solution, describe your algorithm instead. Posting AC code will be penalized.
User avatar
dovier
Posts: 1097
Joined: 6 years ago
Location: Havana, Cuba
Gender: Male
Cuba

1049 - Sum

Post by dovier » 6 years ago




alvarofloresmx
Posts: 1
Joined: 4 years ago
Gender: None specified

Re: 1049 - Sum

Post by alvarofloresmx » 4 years ago

I was wondering if there's any chance this problem might be wrong when interpreting C# answers

I used the custom tool of the Datagen and used my code to compare my answers to the one that was suppose to be. I used different numbers and got it right but whenever I try to submit it it gives me a "Wrong answer" error.

http://imgur.com/bPdBVtv

I could submit my code but well I shouldn't.

User avatar
ymondelo20
Posts: 1968
Joined: 6 years ago
Location: Universidad de las Ciencias Informáticas
Gender: None specified
Contact:

Re: 1049 - Sum

Post by ymondelo20 » 4 years ago

You can post your code, because it´s not accepted.
"Every problem has a simple, fast and wrong solution" OJ's Main Law. ;)

Pedro
Posts: 1
Joined: 3 years ago
Gender: None specified

Problem 1049

Post by Pedro » 3 years ago

I tried this problem a few times, I always get the input and output right, but when I submit the problem in COJ it always judge the answer as wrong.
this is the my code:

#include<iostream>
using namespace std;
int main()

{
int n,sum = 0;

cin >> n;

for(int i = 1; i <= n; i++)
sum = sum + i;

cout << sum;
return 0;
}

I also tried the problem using this formula : (N(N+1))/2
and the same thing happens, The program gives me the right output but COJ still judge it as wrong answer.

Any tips on what I am doing wrong here?

humbertodiaz
Posts: 97
Joined: 4 years ago
Gender: None specified

Re: 1049 - Sum

Post by humbertodiaz » 3 years ago

Hello Pedro. Threads have been created for each exercise ahead of time. This makes it so that exercises on COJ can have links to their respective threads on the forums. I've merged your post into the correct thread since there is no need to create a new one.

Regarding your problem, you may want to read the wording of the exercise very carefully. Does your program give the correct output for all possibles values of N?

User avatar
ymondelo20
Posts: 1968
Joined: 6 years ago
Location: Universidad de las Ciencias Informáticas
Gender: None specified
Contact:

Re: 1049 - Sum

Post by ymondelo20 » 3 years ago

Haaa ... common mistake...
You will punish yourself at the end.
"Every problem has a simple, fast and wrong solution" OJ's Main Law. ;)

User avatar
Jose132
Posts: 47
Joined: 3 years ago
Location: Matanzas - Cuba
Gender: None specified
Contact:

Re: 1049 - Sum

Post by Jose132 » 3 years ago

@Pedro Men, you have to do a slowly read for this problem, that formula is not completely right for this problem.
This is a little help from Matanzas city.
JoseA132 :P
:-) "Behind every code is an enigma" :-)

chicha
Posts: 2
Joined: 3 years ago
Gender: None specified

Re: 1049 - Sum

Post by chicha » 3 years ago

Hi fellows, first, I just use the formula (N*(N+1)/2), then, I read carefully and realize that all numbers don't fix in it, so, i made small "adjustment" for those several cases. I am still getting "Wrong answer" from the site, I really need help :-)
Thanks in advance

HaZard
Posts: 113
Joined: 4 years ago
Location: Camagüey - Cuba
Gender: Male
Contact:
Cuba

Re: 1049 - Sum

Post by HaZard » 3 years ago

@chicha estuve mirando tu solución y el "ajuste" que le hiciste realmente no resuelve el problema pues la suma es de todos los números desde 1 hasta n
teruel

chicha
Posts: 2
Joined: 3 years ago
Gender: None specified

Re: 1049 - Sum

Post by chicha » 3 years ago

@HaZard gracias mil :D

Post Reply

Return to “Problem set”