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: 1096
Joined: Fri Nov 11, 2011 9:32 am
Location: Havana, Cuba
Gender: Male

1049 - Sum

Postby dovier » Mon Feb 06, 2012 1:23 pm




alvarofloresmx
Posts: 1
Joined: Mon May 26, 2014 2:12 am
Gender: None specified

Re: 1049 - Sum

Postby alvarofloresmx » Mon May 26, 2014 2:19 am

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
COJ Administrator
Posts: 1968
Joined: Sun Nov 13, 2011 12:32 pm
Location: Universidad de las Ciencias Informáticas
Gender: None specified
Contact:

Re: 1049 - Sum

Postby ymondelo20 » Wed May 28, 2014 5:24 pm

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: Mon Apr 13, 2015 12:32 pm
Gender: None specified

Problem 1049

Postby Pedro » Mon Apr 13, 2015 12:43 pm

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: Mon Oct 06, 2014 6:25 am
Gender: None specified

Re: 1049 - Sum

Postby humbertodiaz » Mon Apr 13, 2015 5:29 pm

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
COJ Administrator
Posts: 1968
Joined: Sun Nov 13, 2011 12:32 pm
Location: Universidad de las Ciencias Informáticas
Gender: None specified
Contact:

Re: 1049 - Sum

Postby ymondelo20 » Mon Apr 13, 2015 6:17 pm

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: Thu Mar 12, 2015 2:11 pm
Location: Matanzas - Cuba
Gender: None specified
Contact:

Re: 1049 - Sum

Postby Jose132 » Tue Apr 21, 2015 10:53 pm

@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: Fri May 22, 2015 10:55 pm
Gender: None specified

Re: 1049 - Sum

Postby chicha » Fri May 22, 2015 11:13 pm

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: Sun Feb 09, 2014 9:43 am
Location: Camagüey - Cuba
Gender: Male
Contact:

Re: 1049 - Sum

Postby HaZard » Sat May 23, 2015 5:55 pm

@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: Fri May 22, 2015 10:55 pm
Gender: None specified

Re: 1049 - Sum

Postby chicha » Sun May 24, 2015 12:21 am

@HaZard gracias mil :D


Return to “Problem set”

Who is online

Users browsing this forum: No registered users and 1 guest