If you are designing a minesweeper game, you would need to mark each block with how many mines are adjacent to it.
Write a program that places mines in a square grid. And marks each block with the number of mines adjacent to it.
Showing posts with label problem. Show all posts
Showing posts with label problem. Show all posts
Sunday, May 11, 2008
Friday, May 9, 2008
Problem 9 - Palindromes
Write a program to find if a string is a palindrome.
Make it case insensitive.
Eg. "MADAM" - returns true
"ROB" - returns false
"Madam" - returns true
"mADaM" - returns true
"WhaWha"- returns false
Make it case insensitive.
Eg. "MADAM" - returns true
"ROB" - returns false
"Madam" - returns true
"mADaM" - returns true
"WhaWha"- returns false
Tuesday, May 6, 2008
Day 8 - Substring
You are given two strings - haystack and needle.
You have to find the position of the first occurrence of needle in haystack.
Write a function that takes haystack and needle as input and returns the position of the first occurrence of needle or -1 if needle is not found in haystack.
Eg.
haystack = "Once upon a time, there lived a little boy named Jingle!"
needle = "up"
Return Value = 5
If needle = "fox"
Return Value = -1
You have to find the position of the first occurrence of needle in haystack.
Write a function that takes haystack and needle as input and returns the position of the first occurrence of needle or -1 if needle is not found in haystack.
Eg.
haystack = "Once upon a time, there lived a little boy named Jingle!"
needle = "up"
Return Value = 5
If needle = "fox"
Return Value = -1
Monday, May 5, 2008
Day 7 - Who Won?
You are given an array of strings containing a 3 letter country name followed by a hyphen (-) and A 3 digit number. These strings represent the number of points earned by the students of the respective country in a programming competition.
NOTE: There are only 3 countries participating, India, China and USA. The 3 letter code for the countries are IND, CHI and USA respectively.
Write a function that calculates the total number of points scored by the students of IND, CHI and USA and returns a string in the same format with the country code followed by a hyphen followed by the total points scored by the country which has the highest points.
eg
INPUT -> ["IND-32","CHI-33","USA-29","USA-30","IND-12","CHI-34"]
OUTPUT -> "CHI-67"
NOTE: It is guaranteed that the sum of the scores won't be equal.
NOTE: There are only 3 countries participating, India, China and USA. The 3 letter code for the countries are IND, CHI and USA respectively.
Write a function that calculates the total number of points scored by the students of IND, CHI and USA and returns a string in the same format with the country code followed by a hyphen followed by the total points scored by the country which has the highest points.
eg
INPUT -> ["IND-32","CHI-33","USA-29","USA-30","IND-12","CHI-34"]
OUTPUT -> "CHI-67"
NOTE: It is guaranteed that the sum of the scores won't be equal.
Labels:
problem,
program,
programming,
string manipulation
Day 6 - Question : Breaking Strings
You are given a string containing a string Date of Birth in DD/MM/YYYY format. Eg "15/08/1947". Write a function that takes the string as an input and returns a vector containing 3 elements:
v[0] = Day as an integer
v[1] = Month as an integer
v[2] = Year as an integer
eg:
INPUT : "15/08/1947"
Output: [15, 8, 1947]
v[0] = Day as an integer
v[1] = Month as an integer
v[2] = Year as an integer
eg:
INPUT : "15/08/1947"
Output: [15, 8, 1947]
Saturday, May 3, 2008
Day 5 - The second tallest student
Problem - You are given an integer array of heights of students in a class. Write a function that returns the height of the 2nd tallest child in the class.
Friday, May 2, 2008
Day 4 problem - Whats the distance
Here is todays problem.
You have a square grid extending infinitely in all directions. Your home is at point (hx,hy). You have to reach your college located at point (cx, cy). You can only travel parallel to the direction of the X or the Y axis and each step is 1 unit long. Write a program to find the number of steps between your home and your college.
Write it now. Test it. And come back later to check the solution.
You have a square grid extending infinitely in all directions. Your home is at point (hx,hy). You have to reach your college located at point (cx, cy). You can only travel parallel to the direction of the X or the Y axis and each step is 1 unit long. Write a program to find the number of steps between your home and your college.
Write it now. Test it. And come back later to check the solution.
Labels:
geometry,
maths,
problem,
program,
programing,
programming,
Question
Wednesday, April 30, 2008
Day 3 - Programming problem: Shortest height
Question: You are given an array height[] of positive integers containing the heights of the children in a class. Write a function that takes height[] as an input and gives the shortest height as the output.
For example -
Input - [23,29,20,22,23,22,19,25,21,26,23,24,18,30]
Output - 18
Request: Pls take the quiz the right side bar to give feedback on the easiness/difficulty level of the questions. Thanks
For example -
Input - [23,29,20,22,23,22,19,25,21,26,23,24,18,30]
Output - 18
Request: Pls take the quiz the right side bar to give feedback on the easiness/difficulty level of the questions. Thanks
Labels:
c++,
code,
coding,
problem,
program,
programing,
programming
Tuesday, April 29, 2008
Solution to Group 2 Problem
Group 2
View the problem here.
Here we have to add the sum of digits of a number. We can go about doing it by taking taking 1 digit at a time and adding it to the result.

Note: that whenever you write programs like these, always test for boundary conditions. Eg. Will the program work when the input is 0? What if the number is a negative number? etc.
Please click on the image for clarity.
Request: Please take the quiz or leave your comment to help me make this site more useful. Thanks
View the problem here.
Here we have to add the sum of digits of a number. We can go about doing it by taking taking 1 digit at a time and adding it to the result.

Note: that whenever you write programs like these, always test for boundary conditions. Eg. Will the program work when the input is 0? What if the number is a negative number? etc.
Please click on the image for clarity.
Request: Please take the quiz or leave your comment to help me make this site more useful. Thanks
Labels:
c++,
code,
problem,
program,
programing,
programming
Monday, April 28, 2008
Todays Question: Group 3
Que 1.3> Write a program that finds the sum of the digits of a number, using recursion.
Labels:
coding,
problem,
programing,
programming,
Question
Todays Question: Group 2
Que 1.2> Write a program to find the sum of the digits in a number.
Labels:
coding,
problem,
programing,
programming,
Question
Todays Question: Group 1
Que 1.1> Write a program to add 2 numbers.
Labels:
coding,
problem,
programing,
programming,
Question
Subscribe to:
Posts (Atom)