Forum

Post 13.12.2009   # 1
Subject question about 4 task
The returning value of the function in the 4th task is String.

public String smallest(int distance)

I solved the task correctly with integers. How am I supposed to convert integer to string?

Why don't you give the competitors freedom of choosing the returning value?
DiablO is offline Reply
Post 13.12.2009   # 2
I also solved it with integers in c++ and on arena compiler atoi doesn't work!
bojan is offline Reply
Post 13.12.2009   # 3
I tried with itoa to convert integer to string, but unfortunately itoa only works for char [] and not string.
DiablO is offline Reply
Post 13.12.2009   # 4
It works on visual studio 2005, but not on arena compiler! :@
bojan is offline Reply
Post 13.12.2009   # 5
The tasks are carefully examined and the return value is determined based on the expected results and the solving course.

As programmers, you must know how to do this .toStirng() transformation. When this contest finishes, view the other competitors solutions to get some ideas.
hsilomedus is offline Reply
Post 13.12.2009   # 6
Also, the experience gathered from submitting C++ and C# problems will be examined and a "What to use" article will be posted. That way, you will be aware what classes/imports/function you can use and on which environment.
hsilomedus is offline Reply
Post 13.12.2009   # 7
hsilomedus wrote:
The tasks are carefully examined and the return value is determined based on the expected results and the solving course.

As programmers, you must know how to do this .toStirng() transformation. When this contest finishes, view the other competitors solutions to get some ideas.

I still do not understand why you put string as return value. It makes no sense.

As programmer you try to convert integer to string in C++ and if you succeed (I truly doubt) it still doesn't make you good programmer.

Also I do not understand why you implement classes and functions. Why don't you implement iostreams like SPOJ and Z-Training?

Somebody just do not know how to use OOP or vectors or even strings.

You need to improve these things immediately. I guess you should also improve the English language because I can barely understand what the tasks are supposed to mean.

Another thing, it took me 1 hour to convert integer to string (and I did not succeed). Why? Because I have never used strings from the <string> library. I have only used C strings.

Again, if you improve these things you will be way on your go.

Regards.
DiablO is offline Reply
Post 14.12.2009   # 8
hahahahah diablo man you're the funniest person ever hahaaahahahha. Why use code at all? why dont we just write in our own language what we mean and let the compiler understand haahahahah.
Hint: learn some basic stuff and come back asking questions then ...
hahahaha "choose the returning value". How do you suggest we do that?

vasja is offline Reply
Post 14.12.2009   # 9
vasja wrote:
hahahahah diablo man you're the funniest person ever hahaaahahahha. Why use code at all? why dont we just write in our own language what we mean and let the compiler understand haahahahah.
Hint: learn some basic stuff and come back asking questions then ...
hahahaha "choose the returning value". How do you suggest we do that?



Ok, you obviously do not understand what I am talking about. First, if I make the function to return integer value (like in this case) the compiler find errors. So I need to convert the integer value into string so the compiler can accept it? Do you understand now?

If its easy to convert integer into string (and not integer into char []) could you please possibly provide the C++ code here ?

Thanks.
DiablO is offline Reply
Post 14.12.2009   # 10
First of all, this is not z-trening, this is different type of competition, it is more like topcoder, but it is unique. I recommend you to be flexible and to adjust to the competition format and not to wait the competition format to adjust to you.

Second thing, codefu competitions have a tradition of about 3 years, and many competitions have been made. None of the people had something against the competition system, in fact it is really interesting and challenging.

Third, why input and output is not from standard console input output. This part should be advantage to codefu competitions mostly because you don't have to worry if you have parsed the input or output well, and you won't lose time on making your code read and output the input. Everything is defined, you just have to return the result. Same type of solving problems is implemented on topcoder. I don't know how old are you but i suggest you to read more about object oriented programming.

Fourth thing "Why don't you give the competitors freedom of choosing the returning value?". I won't comment this for obvious reasons.

Fifth thing, as you know, English is not our native language, but it is needed for this competition in order to increase the quality, as you can see there are some quality programmers from other countries that can compete if they like. Maybe sometimes English is not so perfect seeing from the side of professional native English speaker. I think English versions of the problems are very good, in fact in all codefu competitions I have participated I didn't have any problems with understanding the problem statements. One of the challenges is also understanding problem statements. For the last competition i can say the all the tasks were fully understandable and other people can confirm it.

Sixth thing, maybe part of the problem is converting to int to string. If you don't know how to use some function you can implement by yourself, for this problem is pretty easy to convert from int to string. If you need 1 hour time to do this, don't blame others, try to improve yourself. Learn to code this or learn to use the methods in the libraries.

On almost all competitions, you don't have time to code Queue, or Stack, or ArrayList, or anything that is needed and that is why libraries exist. Part of the competition is also using the library.

Learn from your mistakes, learn from other codes, learn how you can improve your solutions, read lectures from the internet, work a lot, solve problems. Instead of complaining and being not-objective.

I hope you will understand and use the things i have told you to improve your coding skills and most of all, to be fair and flexible to using new knowledge.
igorkulev is offline Reply
Post 16.12.2009   # 11
Here's my C++ code for the 400 point task. Although it doesn't pass all test cases it converts from int to string correctly
And here you can learn how to do this by yourself. This is one of topcoders excellent tutorials.
http://www.topcoder.com/tc?module=Static&d1=tutorials&d2=standardTemplateLibrary#stringstreams

#include <string>
#include<sstream>
using namespace std;



class Distance
{
public:

int rev(int a)
{
int res=0;
while(a>0)
{
res*=10;
res+=a%10;
a/=10;
}
return res;
}
string smallest(int distance)
{

int i;
int a;

ostringstream os;


for(i=distance;i<=1000000;i++)
{
a=i-distance;
if(rev(i)==a) {os<<i; return os.str(); }
}
return "-1";
}
}
vasja is offline Reply
Post 27.11.2015   # 12

Nen0 is offline Reply

Please login to post reply.