Need help. Answer so i will send the code and problem :s This will let me know that there is actually somebody that want to or can help me.

btw. im' noob in programing

10 years ago*

Comment has been collapsed.

You'd probably have more luck if you just posted the issue for everyone to see.

10 years ago
Permalink

Comment has been collapsed.

meh, will wait couple of minutes more and then i will post

10 years ago
Permalink

Comment has been collapsed.

I can take a look at it for you :)

10 years ago
Permalink

Comment has been collapsed.

You forgot to call free() on your object

10 years ago
Permalink

Comment has been collapsed.

That's C, pleb. You mean operator delete, or operator delete[], as the case may be.

10 years ago
Permalink

Comment has been collapsed.

Real men code in C

10 years ago
Permalink

Comment has been collapsed.

Real men code in assembly

10 years ago
Permalink

Comment has been collapsed.

this!

10 years ago
Permalink

Comment has been collapsed.

Nope, real men use butterflies

10 years ago
Permalink

Comment has been collapsed.

Since everyone seems to have missed the reference: http://xkcd.com/378/

10 years ago
Permalink

Comment has been collapsed.

Real men code in binary

10 years ago
Permalink

Comment has been collapsed.

real men have girlfriends

10 years ago
Permalink

Comment has been collapsed.

*waifu

10 years ago
Permalink

Comment has been collapsed.

real men have beards, girls don't like beards, they LOVE them. Exactly, they <3 them. Half Life 3 confirmed.

10 years ago
Permalink

Comment has been collapsed.

But Gaben doesn't have a beard...

10 years ago
Permalink

Comment has been collapsed.

yes he does / did

10 years ago
Permalink

Comment has been collapsed.

Oh my

10 years ago
Permalink

Comment has been collapsed.

I do!

10 years ago
Permalink

Comment has been collapsed.

real men code in Brainfuck

10 years ago
Permalink

Comment has been collapsed.

All C is valid C++

10 years ago
Permalink

Comment has been collapsed.

Except that when freeing, you don't call your objects destructor (which is bad, mkey)

10 years ago
Permalink

Comment has been collapsed.

So, the problem is i got to write a simple program. It reads "n" numbers and then shows the the numbers that were written by user (i don't know how to say it in english) more than once. Oh, and it got to show them from min to max.

Input: number n, and then numbers from 1 to 100 000 000 in n lines.

Output: The numbers that were written more than once.

Ex: input: 7 1 3 8 3 1 3 172
output: 1 3

Problem: I don't actually know (lol). My program doesn't want to work for 100 000 000 numbers.
Here it is how i did it for 100.
http://ideone.com/vtNW03

10 years ago
Permalink

Comment has been collapsed.

What do you mean it doesn't want to work for 100 000 000 numbers? Does it fail to compile? Does it fail to execute? Does it crash? are there any error messages?

10 years ago
Permalink

Comment has been collapsed.

It crashes, it's like the number i need (100 000 000) is too big :< Tried double and long but didn't work aswell.

10 years ago
Permalink

Comment has been collapsed.

Oh I see now, it's not about entering 100 000 000 numbers but rather about entering numbers up to 100 000 000.
If you don't care about speed and want to keep it simple you could use a linked list, that'd save you a lot of trouble.

Edit:
What I mean by that is that you create a list element for each number entered and then sort it in the list, if it's already there you mark it some way and at the end you output all marked entries.

10 years ago
Permalink

Comment has been collapsed.

Smells like homework problem :P reminds me how I failed half of my students harharhar

If you do this with an array you're just blowing up your stack. Array of 100 million integers just isn't going to fly. Use something like a set or a hashtable.

(well you could dynamically assign memory on the heap; 100 mill integers obviously fits there but not on your typical stack)

10 years ago
Permalink

Comment has been collapsed.

yes, i'm studying and it is homework :p
I'm on first year, and as i said, i'm noob atm. Never heard of hash table

10 years ago
Permalink

Comment has been collapsed.

Thanks for supplying the code! I mean, obviously it was going to be a homework problem, but you saved us from having to ask. :-P

10 years ago
Permalink

Comment has been collapsed.

Let your program read the user input and determine the number of entered numbers (NumbersEntered++;)
Then make an array where you dump all the user input numbers in.
Next make an other array and use a while() loop (or for() is you like) till >=NumbersEntered. During this loop drop a location of array1[NumberEntered] into array2 while sorting them there.

Think this is the shortest and fastest way to process all numbers the user has inputed.

[EDIT]

Just saw your double input thing... Make a 3rd array for that and add a compare for double input when sorting into 2nd array...

10 years ago
Permalink

Comment has been collapsed.

Najlepiej by było gdybyś:

  1. Utworzył dynamiczną tablicę,
  2. Użył break po 2 powtórzeniach danej liczby.

Make dynamic array and use break when you get the same number twice.

10 years ago
Permalink

Comment has been collapsed.

o dynamicznej nie pomyślałem! :o

10 years ago
Permalink

Comment has been collapsed.

O polak, po pierwsze, czy masz określoną ilość ile tych liczb podanych maksymalnie może być?
liczby jak rozumiem maja być podawane pojedynczo po kolei, w takim razie maja być wyświetlane wszystkie po wpisaniu każdej liczby czy po podaniu jakiejś komendy?

Ogólnie to tworzysz vektor, zapisujesz do niego liczbę, jeśli następna liczba jest większa od poprzedniej to umieszczasz ja za tą, i tak dalej, ogólnie wygląda to tak że sprawdzasz po kolei wszystkie liczby w tablicy(vektorze) czy są one mniejsze, jeśli tak to szukasz dalej, jeśli jakaś jest większa lub równa to wstawiasz obecna liczbę przed nią, a jeśli obecnie podana jest największa to dajesz ja na końcu

Innym sposobem byłoby zapisywanie wszystkich liczb do tablicy i użycie jakiejś metody sortowania, ale dla początkującego to może być bardziej skomplikowane niż to co podałem ;)

10 years ago
Permalink

Comment has been collapsed.

Wpisuje liczbę n, która jest liczbą wpisanych linii. W tych liniach znajdują się liczby z zakresu właśnie od 1 do 100 000 000.

Spróbuję też tak jak opisałeś.

10 years ago
Permalink

Comment has been collapsed.

Pewnie chodzi ci o coś nieco innego ale może ci to odrobinę pomoże ;) http://pastebin.com/b2gwMqrB

10 years ago
Permalink

Comment has been collapsed.

So i tried the dynamic version and that just blew my mind.

For ideone: everything is fine.

For Microsoft Visual Studio: doesn't want to show output.

For the site where i send answers: exceeding the limit of memory

edit: nvm, i think i know the problem with my dynamic array

edit: nope, i don't. code: http://ideone.com/0JKHyt

10 years ago
Permalink

Comment has been collapsed.

That array's too huge (line 8). Try the linked list variant I mentioned above, or the hashmap also mentioned above.

10 years ago
Permalink

Comment has been collapsed.

No tak... nie doczytałem, że ty nie chcesz wprowadzać 100000000 liczb tylko w takim zakresie...

10 years ago
Permalink

Comment has been collapsed.

Może dodaj mnie na steam bo masz tam trochę namieszane w kodzie.

10 years ago
Permalink

Comment has been collapsed.

I am not going to answer your questions directly. Rather, I will try to give you a hand and show you a way to learn it. Are you currently assigned to an algorithms and data structures class?

If you teacher allows it, the C++ Standard Template Library (STL) can be incredibly useful. But in order to use it effectively you must understand the theory behind the scenes, tho. As a teacher, I would ask you to implement these yourself, but not right away on the beginning (I suppose?) your first course.

Also, websites such as cplusplus.com, along with your lecture notes and the book used on your class, are your friend when starting.

10 years ago
Permalink

Comment has been collapsed.

Yes i am assigned. I started studying from october.

They never told us about STL thing. Propably from keeping us going on easy mode. And i know this site :p They reffers her very much :p

10 years ago
Permalink

Comment has been collapsed.

Yeah, ask your teacher if you can use STL. If you can, look at "map" or "set".

If you can't, well, what do you know?

  • Allocating 100000000 is a no-no
  • n <<< 100000000
  • Some numbers may repeat so "n" is the worst (or best) case scenario.
  • 0 and -1 are not valid numbers

It may be a slower approach, but it will run ;)

I'm wondering, does the output need to be sorted?

10 years ago
Permalink

Comment has been collapsed.

That's what I was thinking. It's trivially easy if you use map, but if he's just starting out maybe he's supposed to roll his own dynamic solution?

10 years ago
Permalink

Comment has been collapsed.

That's why I give him those ideas (instead of post a pseudocode), to come up with a different approach.
But I guess he didn't have enough time.

10 years ago
Permalink

Comment has been collapsed.

Yeah, most universities do not introduce the STL during the first semester, if at all. It is actually positive, as you are constantly motivated to implement your own structures, and this should eventually result in your own library. Please do it, as it will be useful for the rest of your (under)graduation.

However, I expect every professional to be able to know how to harness its environment, using the tools and libraries available on a programming language. Reinventing the wheel is not always necessary; it depends on your use case / area.

I should mention why I asked about STL before... During my first year, one of the teachers introduced STL during the course as an experiment. I could explain further how this went, but doing so would add little to this thread, so...

Don't worry, all of this should be very well exercised later on.


EDIT: I was going to ask about your difficulty, but I have seen many helped you with it already.... Please let me know if I can help you further.

10 years ago
Permalink

Comment has been collapsed.

Do you need to know how many times each number was used? Or only if it were used more than once?

Currently, you are keeping count of how many times, but that is unnecessary information.

10 years ago
Permalink

Comment has been collapsed.

My program need to show the numbers that were written more than once.

10 years ago
Permalink

Comment has been collapsed.

without testing something like the following should work:

std::map<int,int> wordcount;

int read_value;

while (std::cin >> read_value)

++wordcount[read_value];

for (auto it = wordcount.begin(); it != wordcount.end(); ++it)

if (it->second > 1)

std::cout << it->first << std::endl;
10 years ago
Permalink

Comment has been collapsed.

you forgot the SPOILER ALERT!

10 years ago
Permalink

Comment has been collapsed.

Obviously, but isn't that what he was asking?

Surprisingly it actually runs on the first try.
http://ideone.com/lSTabj

So where's my money?

Btw if anyone is interested in similar problems check project euler:
https://projecteuler.net/
Your teachers might even be getting their exercises there ;)
They start of easy, but are really good at improving your computational math skills

10 years ago
Permalink

Comment has been collapsed.

mmno :/ im programming in vb.net

10 years ago
Permalink

Comment has been collapsed.

lol same. I'm drooling over those C++ code - a bit hard to follow. Too used to read VB codes.

10 years ago
Permalink

Comment has been collapsed.

Say friend, are you going to make a new question next week when you get your next assignment? :) At some point you will have to learn this stuff, best to start now... Good luck! :)

10 years ago
Permalink

Comment has been collapsed.

man, from start of my studying this is the first time i have to ask somebody for help. :<

And thanks

10 years ago
Permalink

Comment has been collapsed.

Because the best way to learn stuff is to not ask for help when you're stuck?

10 years ago
Permalink

Comment has been collapsed.

I might not understand you well but:
i try to learn myself withot any help everytime. It's the best way for me because i learn alot more than i need and i finally solve the problem. But this task wants something from me that i don't see ._.

10 years ago
Permalink

Comment has been collapsed.

If you were ever able to figure it out on your own, you were never stuck. A very important part of learning is gaining knowledge, knowledge of which is given to you either by a teacher, tutor, or from forms of research. This topic would be part of his research.

10 years ago
Permalink

Comment has been collapsed.

Deleted

This comment was deleted 5 years ago.

10 years ago
Permalink

Comment has been collapsed.

while saying noob i meant that i'm new in this, and i try my best to improve as much as i can and even more but, compared to people here i'm noob.

edit: oh and the payment. Pic of my happy face. deal? I mean i don't want the final code from You guys. It would be nice but i want to do it myself.

10 years ago
Permalink

Comment has been collapsed.

I took C++ last year and agree that at a certain point you SHOULD ask for help after you'd tried to solve the problem yourself. My husband is a former programmer so he gave me a two-hour rule - if I could not solve it in two hours, he'd give me some pointers but never a full solution.
Many times I'd look for a similar problem posted on various sites just to give me some insight. Found this one for you...

http://www.cplusplus.com/forum/beginner/1666/

btw, I haven't looked at your code but I'd suggest you go talk to your professor if you're still stuck. It helps them to know where they aren't explaining concepts well enough.

10 years ago
Permalink

Comment has been collapsed.

Well, i don't really like asking for help, it's like a shame for me. I want to do everything by myself. Otherway, i get lazy. But i never refuse to help.

Well while exams in december i got an error also. Professor took a look at my answer and he had to use admin panel to accept my answer. Meh, i guess computers that i like and i want to know more about them and know how to use them more than just playing games, chatting and surfing on internet don't like me :<
Got to send the right answer in 13 minutes :< Guess i will talk to prof. once again :s

10 years ago
Permalink

Comment has been collapsed.

Meh, tried everything i could (also second task is pretty crazy). As i said post before (story about exam) the system where i put answers sometimes just doesn't like me and refuse to work with me (i mean it shows errors on correct answers, programs). Guess i will go to professor and talk with him.

Big thanks for any help, i really appreciate it. Learned some new things from you guys. Definitely as soon as i get some money on paypal i wil make a giveaway just for You guys. Once more, thank You all :)

10 years ago
Permalink

Comment has been collapsed.

10 years ago
Permalink

Comment has been collapsed.

Thanks but 31 minutes late :p I send my answers and i will talk to professor.

10 years ago
Permalink

Comment has been collapsed.

yeap

10 years ago
Permalink

Comment has been collapsed.

Closed 10 years ago by K0NIK0.