chang.advits.com



May 21, 2012, 09:26:08 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Welcome to this forum
 
Pages: [1]   Go Down
  Print  
Author Topic: Programming Contest Questions  (Read 699 times)
0 Members and 2 Guests are viewing this topic.
Chang Gee Guan
Administrator
Jr. Member
*****

Karma: 0
Offline Offline

Posts: 69



View Profile
« on: August 08, 2008, 06:58:32 PM »

well, just got the FTMK Programming contest answers.
may be u all can have a look.
i m currently working on these set of problems, lets see how many i can able to solve.  Grin
Logged
Chang Gee Guan
Administrator
Jr. Member
*****

Karma: 0
Offline Offline

Posts: 69



View Profile
« Reply #1 on: August 08, 2008, 07:03:28 PM »

The First Question:

Adding Reversed Numbers

The Antique Comedians of Malidinesia prefer comedies to tragedies. Unfortunately, most of the ancient plays are tragedies. Therefore the dramatic advisor of ACM has decided to transfigure some tragedies into comedies. Obviously, this work is very hard because the basic sense of the play must be kept intact, although all the things change to their opposites. For example the numbers: if any number appears in the tragedy, it must be converted to its reversed form before being accepted into the comedy play.

Reversed number is a number written in arabic numerals but the order of digits is reversed. The first digit becomes last and vice versa. For example, if the main hero had 1245 strawberries in the tragedy, he has 5421 of them now. Note that all the leading zeros are omitted. That means if the number ends with a zero, the zero is lost by reversing (e.g. 1200 gives 21). Also note that the reversed number never has any trailing zeros.

ACM needs to calculate with reversed numbers. Your task is to add two reversed numbers and output their reversed sum. Of course, the result is not unique because any particular number is a reversed form of several numbers (e.g. 21 comes from 12,120,1200....). Thus we must assume that no zeros were lost by reversing (e.g. assume that the original number was 12).

Input Specification
The input consists of N cases. The first line of the input contains only positive integer N. Then follow the cases. Each case consists of exactly one line with two positive integers separated by space. These are the reversed numbers you are to add.

Output Specification
For each case, print exactly one line containing only one integer - the reversed sum of two reversed numbers. Omit any leading zeros in the output.

Sample Input:
3
24 1
4358 754
305 794

Output for the Sample Input:
34
1998
1
« Last Edit: August 08, 2008, 07:17:15 PM by Chang Gee Guan » Logged
Chang Gee Guan
Administrator
Jr. Member
*****

Karma: 0
Offline Offline

Posts: 69



View Profile
« Reply #2 on: August 08, 2008, 07:27:11 PM »

The first question is very easy,
so let me give the answers since i manage to solve it.

Code:
#include <cstdlib>
#include <iostream>

using namespace std;

int fnReverse(int);

int main(int argc, char *argv[])
{
    int iCases =0, firstNum, secNum;
    int revAns[100] = {0};
   
    cin>>iCases; /*get number of test cases*/
   
    /*loop for number of cases*/
    for(int iLoop=0;iLoop<iCases;iLoop++)
    {
         cin>>firstNum>>secNum;
         /*get the reverse of the reversed num1 + reversed num2*/
         revAns[iLoop]=fnReverse(fnReverse(firstNum)+fnReverse(secNum));
    }
   
      for(int iLoop=0;iLoop<iCases;iLoop++) /*print out the answers*/
         cout<<revAns[iLoop]<<endl;
   
    system("PAUSE");
    return EXIT_SUCCESS;
}


int fnReverse(int aNum)  /*This function reverces any given integer*/
{
    int rev = 0;
   
    do
         rev = (rev*10) + (aNum%10) ;
    while(aNum/=10,aNum!=0);
   
    return rev;
}

btw, this is C++ code.
Logged
Chang Gee Guan
Administrator
Jr. Member
*****

Karma: 0
Offline Offline

Posts: 69



View Profile
« Reply #3 on: August 08, 2008, 07:29:51 PM »

here comes the next question:

Copying Books

Before the invention of book-printing, it was very hard to make a copy of a book. All the contents had to be re-written by hand by so called scribers. The scriber had been given a book and after several months he finished its copy. One of the most famous scribers lived in the 15th century and his name was Xaverius Endricus Remius Ontius Xendrianus (Xerox). Anyway, the work was very annoying and boring. And the only way to speed it up was to hire more scribers.

Once upon a time, there was a theater ensemble that wanted to play famous Antique Tragedies. The scripts of these plays were divided into many books and actors needed more copies of them, of course. So they hired many scribers to make copies of these books. Imagine you have m books (numbered 1, 2 ... m) that may have different number of pages (p1, p2 ... pm) and you want to make one copy of each of them. Your task is to divide these books among k scribes, k <= m. Each book can be assigned to a single scriber only, and every scriber must get a continuous sequence of books. That means, there exists an increasing succession of numbers 0 = b0 < b1 < b2, ... < bk-1 <= bk = m such that i-th scriber gets a sequence of books with numbers between bi-1+1 and bi. The time needed to make a copy of all the books is determined by the scriber who was assigned the most work. Therefore, our goal is to minimize the maximum number of pages assigned to a single scriber. Your task is to find the optimal assignment.

Input Specification
The input consists of N cases. The first line of the input contains only positive integer N. Then follow the cases. Each case consists of exactly two lines. At the first line, there are two integers m and k, 1 <= k <= m <= 500. At the second line, there are integers p1, p2, ... pm separated by spaces. All these values are positive and less than 10000000.

Output Specification
For each case, print exactly one line. The line must contain the input succession p1, p2, ... pm divided into exactly k parts such that the maximum sum of a single part should be as small as possible. Use the slash character ('/') to separate the parts. There must be exactly one space character between any two successive numbers and between the number and the slash.
If there is more than one solution, print the one that minimizes the work assigned to the first scriber, then to the second scriber etc. But each scriber must be assigned at least one book.

Sample Input
2
9 3
100 200 300 400 500 600 700 800 900
5 4
100 100 100 100 100

Output for the Sample Input
100 200 300 400 500 / 600 700 / 800 900
100 / 100 / 100 / 100 100

how to solve it???  Huh
Logged
Jath
Administrator
Newbie
*****

Karma: 0
Offline Offline

Posts: 22


Jathniel Tong


View Profile WWW
« Reply #4 on: August 09, 2008, 06:09:28 PM »

hahaha... td maseh ade mood nk solve but.... lps ternmpk ques yg xde ends tu.. hahaha,,, cpt2 lari, tutup browser. wakakkaa  Grin
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by SMF 1.1.6 | SMF © 2006-2008, Simple Machines LLC