- Strength to Increase Rep
- +0
- Strength to Decrease Rep
- -0
- Upvotes Received
- 2
- Posts with Upvotes
- 2
- Upvoting Members
- 2
- Downvotes Received
- 0
- Posts with Downvotes
- 0
- Downvoting Members
- 0
37 Posted Topics
Re: also can be done recursively..but stack almost equals recursion... for example: [code=c++]#include <iostream> #include <string> using namespace std; void do_the_stuff() { char c; c = getchar(); if( c == '\n' ) return; do_the_stuff(); putchar( c ); } int main( void ) { cout << "Enter:" << "\n"; do_the_stuff(); return 0; … | |
okay, i don't have a problem coding the game... that part would be easy. but the problem is to output the lease number of rotations needed to complete the game, so for example... 123 => 413 456 => 526 789 => 789 (rotation of the top left corner) that's what … | |
Re: ehh, now i'm confused... it would be helpful to see some code you've done already, but this is my suggestion: don't use a stack. it's a maze... a pretty straightforward graph. if you know where you should start, and where you should finish, you bfs through the graph, keeping track … | |
Re: [QUOTE=Code Shark;722383] As title says is this code ok or should i do it another way?[/QUOTE] depends on what it's supposed to do :) | |
Re: hmm, define test case...? i don't get it... you can write some numbers onto a piece of paper, add them up and divide by the their quantity... enter those numbers into your program and check if the results match! | |
Re: hmmm...lemme analyze this abit: [code]#include <iostream> #include <cmath> using namespace std; const int MAX = 10 + 1; //let it have more space //Main Module int main() { int A[MAX] ; // declare the size of the array int sum ; // declare sum as integer float mean ; // … | |
heya... ok, so i was browsing the net to find out if there's a good text on this algorithm, but i don't seem to be able to find one. people are obviously using it, but, hey, there's no info on it. the part i get is the theory on how … | |
okay, so i came up with this idea of making a program to evaluate my code. it's supposed to take the code, compile it, run it on several test cases (given in one file each) and report how the code did (which test cases it passed, which cases it failed...) … | |
okay...i've got another wired counting problem, this time it's about rectangles! gotta find the minimum number of lines to divide a rectangle into squares! i went for...ehh well a dumb idea of cutting the max square off, and cutting the little ones recursively, but... doesn't always work. you're given the … | |
Re: you can access them by memory addresses... so the integers should be given addresses that are consecutive. could count as pointing really. | |
Re: yea, you gotta either macro it or typedef with specifying the actual template type :P sucks in a way... but hey, what's the deal with the box thing, it's pretty small and easy to write... i use typedef for long, looooong names, like: [code=c++] typedef my_monumental_structure<another_huge_type>::iterator sit;[/code] and then i … | |
okay, this is the problem (variation of the knapsack coins problem): you've got 4 coin types: 1 cent, 2 cents, 5 cents and a quarter...infinite amount of each. I'm supposed to find the number of ways in which the coins can be arranged to form the sum of some integer … | |
Re: if you could post a more detailed description of the problem... if you're only working with square binomials it should be really simple. for example, if the shape of the input is ax^2 + bx + c, all you have to do is isolate a, b, and c, solve the … | |
Re: well... i'm not that good with c++ I/O (c ftw), but if you're using fstream, you can make two streams and use them for I/O, for example if the input stream is called 'input' you can go with [code=c++]while( input >> aa ) {/*blahblah...*/}[/code] ...well i guess you can... hmm, … | |
Re: well this is a simple implementation of the sieve... [code=c++]#include <cstdio> #define MAX 100000 bool prime[ MAX ]; void sieve() { for( int i = 0; i < MAX; ++i ) prime[i] = 1; prime[1] = 0; for( int i = 2; i < MAX; ++i ) for( int j … | |
every time i make my own rounding routine with precision, i see my compiler suggesting a function long double round(long double x, int precision); so i was wondering if someone knows what library it comes from, i surely wasn't able to find it... thanks | |
Re: well if you know the exact position of those chars you can easily extract them from the string you read them in... for example, the given the position and length of the integer, you could go with something like this: [code=c++]#include <cstdio> char str[ 256 ]; int pos, len, sol … | |
i got myself a big pile of components yesterday, an amd dual core procesor, a new motherboard (biostar ta770 a2+) and a new graphics card, nvidia(club3d geforce 9600gt overlocked). so now i've put it all together, the computer starts normally but i don't get any output on my monitor, the … | |
ok, so this is my problem... i have an array of items, which i want to sum to x or above in a most efficient way... is there a way for doing this? cause all the values are 64 bit ints. i tried recursion but it's slow cause i can … | |
given two arrays of n numbers, a[] and b[], and a number c, find the largest sum of elements from a[] so the sum of same-indexed elements from b[] don't go over c... i really have no idea... only recursion works but too slow :( heeeeelp! | |
could someone please tell me if there are local stores in NY where i can get this calculator? if there are can i please have the adress or something? thanks. | |
okay, so i gotta make a good enough hash function that should be able to make me a key for out of two integers ( -1000000 <= x, y <= 1000000 ), and should work...well atleast 80% of the time so i could store these in an one-dimensional array... i've … | |
okay so i've got n and an array of n numbers, i have to go through all the three's of numbers like a[i], a[j], a[k] so that i < j < k and take the maximum of each such numbers (max of a[i], a[j], a[k]). my first guess is three … | |
Re: Umm, system() calls don't work on all platforms... you can use cin.get() but i think it executes every time you press enter so you might need an army of those. for example: [code=C++]#include <iostream> int main( void ) { int a; std::cin >> a; std::cout << a; std::cin.get(); return 0; … | |
the problem is to find the minimum numbers to be popped from an array to make it sorted. so for example 12534756, you can pop all but one, but it's best to pop 5 and 7 cause it's the least needed to make it sorted. I'm having difficulties finding a … | |
Re: I'll just hope you're not in highschool yet so...here's the first function you'll need...it's pretty straightforward: [code]char letter( int mark ) { if( mark <= 39 ) return 'F'; else if( mark <= 49 ) return 'E'; else if( mark <= 59 ) return 'D'; else if( mark <= 69 … | |
Re: i don't know any alternative way of clearing the screen...so i guess this code of mine is not portable but it works...in a more fancy way. [CODE]#include <iostream> #include <conio.h> #define MAX 256 int main() { using namespace std; char ch, len; while ((ch = getch()) != '\r') { if( … | |
Re: nothing fancy, if you know how to convert a binary representation to decimal on paper...just implement that! i'd use a string to input 1's and 0's but you can use a long long or something using a simple algorithm to seperate digits: [CODE]#include <iostream> using namespace std; int main( void … | |
Re: namespaces are generaly used to avoid conflicts that could happen if you have two functions, classes, etc. with a same name... so if you've got a libraries "libA" and "libB" and in each of those you have a function named "f" you need a way to know which function you … | |
Re: I guess this could help also... i don't know how really clever this is but why not use all the nice stuff STL gives? for example you could use a set structure to check when the cyclic array of numbers starts to repeat by inserting results into it and checking … | |
Re: Depending on the spacing...(if it doesn't matter) you can use a LIFO stack... I'd use the STL stack...the code would look like this: [CODE]#include <iostream> #include <string> #include <stack> using namespace std; stack<string> sstack; string word; int main( void ) { while( cin >> word ) sstack.push( word ); while( … | |
Re: i guess xor swapping could do here too, no need for another variable! slightly fancier code: [CODE] for (j = 0, i = word.size() - 1; j < i; --i, ++j) { word[i] ^= word[j]; word[j] ^= word[i]; word[i] ^= word[j]; }[/CODE] or even simplier [CODE] for (j = 0, … | |
given x and y (the field dimensions) and x*y numbers, (pieces of cheese on each square) calculate the best way for the mouse to get from (1, 1) to (x, y), he has to get as many cheese as possible... also you can only move closer to the (x, y) … | |
I guess there is a "standard" algorithm for problems of this type.. the template would look like this: given the integer n and n numbers, find the smallest sum you can get by adding the numbers like this: n1+n2+n1+n2+n3+n1+n2+n3+n4... the obvious way for me was to do some math on … | |
Okay, so i got the volume I of Sedgewick's Algorithms in C++ and I'm pretty much lost in the first chapter. I understand all the given examples and such things but the exercises seem impossible. I'm still just starting highschool and the math used there aren't that easy and the … | |
a mouse is trapped in a labyrinth.. and he has to find the cheese! the input is W and H (height and width), and a graph like this one: [CODE] ##...# C###.. ...... .####. .....M [/CODE] i'm supposed to calculate the shortest amount of steps he needs to make to … | |
I've started programming a few months ago, i've done basic before, then i tried pascal for a while but now i'm comfortable with C++. The problem is, i'm trying to learn as much as i can from the net and books, but i can't find a good book i could … |
The End.