cprogramming

Algorithmic Programming with C III

On June 4, 2011, in Computer Science, Programming, by d0m3z

Facebook Hacker Cup (Qualification Round / Q1)

Double Squares

A double-square number is an integer X which can be expressed as the sum of two perfect squares. For example, 10 is a double-square because 10 = 3*3 + 1*1. Your task in this problem is, given X, determine the number of ways in which it can be written as the sum of two squares. For example, 10 can only be written as 3*3 + 1*1 (we don’t count 1*1 + 3*3 as being different). On the other hand, 25 can be written as 5*5 + 0*0 or as 4*4 + 3*3.

(more…)

 
cprogramming

Algorithmic Programming with C II

On June 4, 2011, in Computer Science, Programming, by d0m3z

Guidelines: The following exercises are to evaluate students’ understanding in the following topics (as essential programming concepts):

  • Basic I/O functions (5%)
  • Selection structure (20%)
  • Repetition structure (20%)
  • Arrays and strings (20%)
  • Functions (10%)
  • Programming techniques (25%)

Each question does not require external libraries or any special knowledge except for basic I/O functions. Skillful students should complete both question within only 20 minutes, while some students may take up to an hour.

Q1. Write a program that takes a string as an input, passes the string to a function which swaps the first 2 vowels of the string, and then prints the result as the output. The input string is assumed to consist only of lower-case letters and have its length of less than 32 characters. The program, however, must meet the following specifications:

(more…)

 
cprogramming

Algorithmic Programming with C

On June 4, 2011, in Computer Science, Programming, by d0m3z

Write a function that performs searching for a string in a piece of text. The string for which to be searched, however, may contain asterisks (*) representing a wildcard for any sequence of characters or none.

The followings are expected outputs:

search(“This is a book”, “book”); // returns true
search(“This is a book”, “books”); // returns false
search(“This is a book”, “t*is a”); // returns true
search(“This is a book”, “is*his*oo”); // returns false
search(“This is a book”, “th*s*ok”); // returns true

(more…)