|
|
#1 | ||||||||
|
Junior Member
|
I have been learning C++ for over a year now and I would like to ask the community for some C++ coding challenges or puzzles. My professors have given me ones such as ...
int strlen(char * sz) { } note: solution only took 3 lines using (recursion) OR "Write a C function that multiplies an input integer by 5 and returns the result. The function must not use the multiplication operator. Optimize for speed." I believe this one actually goes into the bits. Anyways, I wonder if you could share some of yours in hopes of challenging others. |
||||||||
|
|
|
|
#2 | ||||||||
|
Senior Member
Location: CT |
http://www.codechef.com/
Up top you'll see a "Practice" tab which will provide problems to solve. There are even competitions in which you can enter. It's a great site. |
||||||||
|
|
|
|
#3 | ||||||||
|
Junior Member
|
Here is a whiteboard C coding question I was asked at an actual game company interview. Complete this function:
Code:
bool IsPalendrome(char* str)
{
}
|
||||||||
|
|
|
|
#4 | ||||||||
|
Administrator
Location: UK |
Try the demo test on http://codility.com/
__________________
Steven Yau [Alix Games Blog] [Portfolio] [How I broke into the Games Industry] [Why I left my Games Job] [How to be a Games Tester] [Getting back into the Game] |
||||||||
|
|
|
|
#5 | |||||||||
|
Senior Member
Location: CT |
Quote:
|
|||||||||
|
|
|
|
#6 | ||||||||
|
Administrator
Location: UK |
The free demo test itself is usually pretty decent. Codility is for the hiring managers to sends tests out rather then preparing for interviews.
__________________
Steven Yau [Alix Games Blog] [Portfolio] [How I broke into the Games Industry] [Why I left my Games Job] [How to be a Games Tester] [Getting back into the Game] |
||||||||
|
|
|
|
#7 | |||||||||
|
Junior Member
Location: UK |
Quote:
I saw this last night while browsing, and it's a nice little problem, if not especially taxing. As a novice, I originally thought it would be best to break it down into an array and do something complicated such as reversing the order of the array and then comparing them. But there is no need - after further reading, having seen the string tools available. Once I was thinking along those lines, it took about 20 mins. So here's a solution (in python rather than C) - anyone got any optimisation tips? Code:
#!/usr/bin/python
def isPalindrome(string):
length = len(string)
#print length
i=0
j=length
while j > 0:
if string[i] == string[j-1]:
#print string[i],string[j-1]
i=i+1
j=j-1
else:
print 'Not a palindrome'
break
if j == 0:
print 'Word is a palindrome'
else:
pass
input = raw_input()
isPalindrome(input)
Last edited by Tonsko : 12-23-2010 at 06:24 AM. |
|||||||||
|
|
|
|
#8 | ||||||||
|
Moderator
Location: Netherlands |
As for "optimizations", instead of, "while j > 0", you could use, "while j > length*.5", since you've already checked the first n/2 letters of the word. :P
(I might be off by one. Sorry for that, if so.)
__________________
I'm a web developer by profession, but a game developer by heart. Uh oh! The princess is in another signature! |
||||||||
|
|
|
|
#9 | |||||||||
|
Administrator
Location: UK |
Quote:
Code:
int strlen(char * sz)
{
if((*sz)!='\0') return (strlen(++sz)+1); else return 0;
}
__________________
Steven Yau [Alix Games Blog] [Portfolio] [How I broke into the Games Industry] [Why I left my Games Job] [How to be a Games Tester] [Getting back into the Game] |
|||||||||
|
|
|
|
#10 | |||||||||
|
Junior Member
|
Well, depends on the definition of optimization:
Code:
def isPalindrome(string):
#More of a C-style optimization for memory usage
for i in range(len(string)/2): #rounds down, which is OK because middle letter can be ignored
if string[i] != string[-i-1]:
return False
else: return True
def isPalindrome(string):
#Optimizes developer time XD
return string == reverse(string)
![]() Quote:
Last edited by cowsonparade : 02-24-2011 at 08:43 AM. Reason: Code, not quote |
|||||||||
|
|
![]() |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
Powered by vBulletin® Version 3.6.9
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
All times are GMT -8. The time now is 08:56 AM.































Linear Mode

