That's C, pleb. You mean operator delete
, or operator delete[]
, as the case may be.
Comment has been collapsed.
Since everyone seems to have missed the reference: http://xkcd.com/378/
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
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.
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)
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
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...
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 ;)
Comment has been collapsed.
Pewnie chodzi ci o coś nieco innego ale może ci to odrobinę pomoże ;) http://pastebin.com/b2gwMqrB
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
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.
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?
It may be a slower approach, but it will run ;)
I'm wondering, does the output need to be sorted?
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.
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;
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
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.
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.
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.
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
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 :)
Comment has been collapsed.
16,299 Comments - Last post 11 minutes ago by Carenard
82 Comments - Last post 4 hours ago by WaxWorm
56 Comments - Last post 7 hours ago by Carenard
1,811 Comments - Last post 7 hours ago by ngoclong19
72 Comments - Last post 9 hours ago by Reidor
545 Comments - Last post 11 hours ago by UltraMaster
41 Comments - Last post 11 hours ago by ViToos
49 Comments - Last post 4 minutes ago by Cim
117 Comments - Last post 16 minutes ago by Cole420
8 Comments - Last post 43 minutes ago by StrangeAsAngels
17 Comments - Last post 1 hour ago by someonequeer
92 Comments - Last post 1 hour ago by Axelflox
72 Comments - Last post 1 hour ago by eeev
9,531 Comments - Last post 2 hours ago by NoYeti
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
Comment has been collapsed.