Showing posts with label tutorials. Show all posts
Showing posts with label tutorials. Show all posts

Tuesday, August 18, 2009

SMS Typing

0 comments

Of late I have been solving a lot of problems. Here s a problem which you guys can solve.

Cell phones have become an essential part of modern life. In addition to making voice calls, cell phones can be used to send text messages, which are known as SMS for short. Unlike computer keyboards, most cell phones have limited number of keys. To accommodate all alphabets, letters are compacted into single key. Therefore, to type certain characters, a key must be repeatedly pressed until that character is shown on the display panel.

In this problem we are interested in finding out the number of times keys on a cell phone must be pressed to type a particular message.

In this problem we will assume that the key pad of our cell phone is arranged as follows.

---------------------

| | abc | def |

---------------------

| ghi | jkl | mno |

---------------------

| pqrs | tuv | wxyz |

---------------------

| |sp | |

---------------------

In the above grid each cell represents one key. Here SP means a space. In order to type the letter ‘a’, we must press that key once, however to type ‘b’ the same key must be repeatedly pressed twice and for ‘c’ three times. In the same manner, one key press for ‘d’, two for ‘e’ and three for ‘f’. This is also applicable for the remaining keys and letters. Note that it takes a single press to type a space.


Input:
The first line of input will be a positive integer T where T denotes the number of test cases. T lines will then follow each containing only spaces and lower case letters. Each line will contain at least 1 and at most 100 characters.


Output:
For every case of input there will be one line of output. It will first contain the case number followed by the number of key presses required to type the message of that case. Look at the sample output for exact formatting.


Sample Input : Sample Output

welcome to ulab : 29

good luck and have fun : 41


Problemsetter: Shamim Hafiz

Special Thanks: Sohel Hafiz

You can download the solution done by me and my friend amruth at here.
The code was compiled and executed on a gcc compiler

Read More......

Monday, August 17, 2009

Bash SpellChecker

0 comments

Reason for this post is that i tend do a lot of typing mistakes while typing at the terminal:-).
Spell checking in bash can be enabled adding the following line below into your bashrc file

shopt -s cdspell

#pradeep@pradeep-laptop:gedit ~/.bashrc

Add the command mentioned above to the end of the file and save.

That’s all :)

If you want to enable this for all the users, then append this to your /etc/bash.bashrc (in Ubuntu) or /etc/bashrc (in Fedora). Of course, you need the root privilege to edit the files in /etc.

Now try these
cd /hoem
cd /hoe

Ain't it cool.

So by the way what is a bashrc file?
Ok in short it is a script which is run by the bash shell when ever a terminal is invoked once you login.
To know more please see /usr/share/doc/bash/INTRO.gz as in "Ubuntu 9.04". Not sure about other versions. It should be the same according to me.


Read More......

Wednesday, August 5, 2009

Install Apache webserver,mysql,perl and php

7 comments

For all those who dont have apache server,mysql,perl and php on your Linux OS here's a way you can install.
People who have installed Fedora 8/9[Full installation] all the above gets installed automatically. But if you have installed other distributions like Ubuntu, Open SUSE, Red Hat etc, here is a way you can do.

If you install the above softwares separately its a very tedious job believe me. But you need not do that. The idea was suggested by my class mate Abdul Munim. There is a package by name XAMPP which installs everything including many cool things.So how do you go about it

So wat is XAMPP??
XAMPP is an easy to install Apache distribution containing MySQL, PHP and Perl. XAMPP is really very easy to install and to use - just download, extract and start.

So how do you go about it?
At first you need to download the package file.You can find the file: here
Now copy the file to your home directory.Now you are three steps away:-)

Step 1: Installation
Go to a Linux shell and login as the system administrator root:
#su

Extract the downloaded archive file to /opt:
#pradeep@pradeep-laptop:tar xvfz xampp-linux-1.7.1.tar.gz -C /opt

Warning 1: Please use only this command to install XAMPP. DON'T use any Microsoft Windows tools to extract the archive, it won't work.
Warning 2: already installed XAMPP versions get overwritten by this command.

Step 2: Start
To start XAMPP simply call this command:
pradeep@pradeep-laptop:/opt/lampp/lampp start

You should now see something like this on your screen:
Starting XAMPP 1.7.1...
LAMPP: Starting Apache...
LAMPP: Starting MySQL...
LAMPP started.


Step 3: Test
OK, that was easy but how can you check that everything really works? Just type in the following URL at your favourite web browser:

http://localhost

Now you should see the start page of XAMPP containing some links to check the status of the installed software and some small programming examples.

You are done now. If you any queries/problems regarding the installation,please post in the comments and i will try to fix the problem:-)

Read More......