oh wel, its over now. They disabled our internet access when it started. I finished 2 of the programs, anfd the judges has only one of them work with their data
yeah. A local university put on a programming contest in C++ or java (you got to choose) and I went as a guest. Only two other people showed up from our school, so I got promoted to a competitor even though I barely know c++. There were 10 probelsm you could do, the one who did the most in the leat amount of time won. The problems had you read a file of a given format, do something with the gathered data, then make an output file. The judges would look at the output file generated by their input file to see if you succeeded. A could of the problems were really tough, like one where you were given a grid in one file:
5
5
(5x5 grid)
and you were supposed to make a spiral of sequencial numbers:
(look at the order of the numbers if you are confused)
I got one of them correct, and came close to a hard one, but ran out of time. The winners (who all had 7 correct) each got a Dell laptop and a scholarship to the university.
DAMN THATS A NICE PRIZE!!!!! heh but Im guessing most are college aged with a lot of experience. Thats really cool that you have stuff like that near you
how much time were you given? (I really wish they'd have something like this near us!)
It was just us high schoolers from around florida. Its a pretty good college (embry-riddle) that deals with mostly aviation, about a 20 min drive.
We had 3 hours to answer 10 problems in colsole applications.
I posted a question on this a couple of days ago too. Havn't got an answer either but I have managed to work out how to do some of these functions myself. Here is what I have got for doing Mid():
Code:
#include <string>
using namespace std;
string Mid(string, long, long);
string Mid(string String, long Start, long Length){
string result;
Start--;
result = String.assign(String, Start, Length);
return result;
}
The reason I have got Start-- is so the first character can be number 1 like in VB.
This works.
This might be a $#!+ way of doing it, but it's hard to get an answer in this forum. Hope it helps.
nstr=str; // store starting address of str in nstr
nstr=str+f; // point to f th position of string
*nstr='\0'; // assign \0 at that position, so indicate end of string by force!
nstr=str; // again store starting address of str in nstr
str=str+s-1;// modify str's starting address to begin from s th position
return str; // return address of str, it now contains required mid string
}
Life is a one way journey, not a destination. Travel it with a smile and never regret anything.
Yesterday is history, tomorrow is a mystery, today is gift - that's why we call it present.
memcpy should do the trick
target=memcpy (target, source+offset,length);
Use
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Originally posted by Alan777 I posted a question on this a couple of days ago too. Havn't got an answer either but I have managed to work out how to do some of these functions myself. Here is what I have got for doing Mid():
Code:
#include <string>
using namespace std;
string Mid(string, long, long);
string Mid(string String, long Start, long Length){
string result;
Start--;
result = String.assign(String, Start, Length);
return result;
}
The reason I have got Start-- is so the first character can be number 1 like in VB.
This works.
This might be a $#!+ way of doing it, but it's hard to get an answer in this forum. Hope it helps.
I think you're doing it the only way it can be done.
You would have to create some algorithm, that simple "goes left", then "goes up" etc.
I can't see how this could be done with loops.
Well, not without a huge number of if statements - in which case you'd be nearly better off just writing out the numbers
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
No, because it needs to be dynamic. Look at the code I attached (a little bit above). It is the whole code needed to solve that, and the main algorithm contains one for loop, one switch and 4 if. Not that much.
All the buzzt CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Basically, you do it by creating nested squares, and then fill those squares.
So if you had a 3x3 box thang, it'd be :
So you would go around the outer box, and then go around each nested box.
If the total number of elements is odd, then you will have a square with one element in the middle.
Otherwise, you will have four elements in the middle.
So for a 4x4 box :
You would go around the outside, counting upwards.
And then move into the inner box, and again, count upwards from the top left.
So you could probably use a recursive function to do the counting in each box and sub box.
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
Problem is, my code is really fast for the method it uses (which has a theoretical difference to your algorithm but no practical), the only good way to speed it up would be a formula that you pass the x and y dimensions and the x and y coordinates and it would return the number there, without loops or such a thing.
Like:
int getatxy(int x, int y, int sizeX, int sizeY);
int i = getatxy(3,3,5,5);
So i would be 25.
This speeds it up because only then you can go line by line left to right and output the data. Any other way and you have to store it in a temporary 2d array (as I did) or use some sort of gotoxy function (which requires stupid calculations where to go).
All the buzzt CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
jim, no you misunterstood this. The problem we're trying to solve is stated somewhere early in this thread. It goers like this.
Read in two integers a,b. Then output a table with dimensions axb with the fields filled with increasing numbers starting at 1, going around the box in a spiral.
E.g. if the input is 5, 6 then output
there's 4 quadrants in the spiral in which the numbers are incrementing in 4 different directions. I decide to call them A,B,C and D in the order they are passed trough from start. A the top quadrant, B the right C the bottom D the left. My function f(x,y) retrieves the value in the incrementing spiral depending on in which quadrant, which revolution and the position in the quadrant relative to just passed corner.
To efficiently determine quadrant we first determine the excentricity of the rectangle e=W>H, the smaller side quadrants should be triangle shaped while the larger side quadrant should be trapezoids, and it would be easier to determine if it were in the triangles first and then determine which side of the half of the rectangle if not in the triangles. The special case when theres a hole in the middle E, when W and H are not even is left when all else fails.
The quadrant Q(x,y)={
if not e:
A if |floor((W-1)/2)|-y<=floor((W-1)/2)
C if |floor(W/2)|+y-H+1<=floor(W/2)
B if x>ceil(W/2)
D if x<floor(W/2)
E if none of the above
if e:
B if |floor((H-1)/2)|+x-W+1<=floor((H-1)/2)
D if |floor(H/2)|-x<=floor(H/2)
B if y>ceil(W/2)
D if y<floor(W/2)
E if none of the above
}
A and C side length are W-1 decrementing with 2 each revolution
similarly B and D are H-1-2R
each full revolution is thus 2(H+W)-8R, and the cumulative sum is
2R(H+W)-8*sumof(R)=2(H+W)-4R(R-1)
The revolution R for the quadrants are
y for A
W-x-1 for B
H-y-1 for C
x for D
and the position P is
x-y for A
y-W+x for B
W-x+y for C
H-y-x for D
The value should be 2R(H+W)-8*sumof(R)=2(H+W)-4R(R-1) + S + P
where S=
0 for A
W-1-2R for B
W+H-2-2R for C
2W+H-3-2R for D
Use
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
forgot to mention, W and H are the grid dimensions, f(x,y) should be W*H for E obviously
Use
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
lots of ifs and stuff, I think writing it in SQ would look considerably cleaner and consise
Use
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.