Thread: i'm having trouble to program this!! SOS reply asap

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    8

    Unhappy i'm having trouble to program this!! SOS reply asap

    Standard telephone keypads contain the digits 0 through 9. The numbers 2 through 9 each have three letters associated with them.

    Many people find it difficult to memorize phone numbers, so they use the correspondence between digits and letters to develop eight-letter words that correspond to their phone numbers. For example, a person whose telephone number is 4263-7663 might use the correspondence in Table 1 to develop the eight-letter word “HANDSOME” so that people can easily remember his phone number. Each eight-letter word corresponds to exactly one eight-digit telephone number. A delivery service could surely do so with the number 3354-8379 (i.e. “DELIVERY”).

    Each eight-digit phone number corresponds to many separate eight-letter words. Unfortunately, most of these represent unrecognizable juxtapositions of letters. It is possible, however, that the owner of a barber shop would be pleased to know that the shop’s telephone number, 4247-2888, corresponds to “HAIRCUTS”. A hospital with the phone number 4677-4825 would be pleased to know that the number corresponds to the letters “HOSPITAL”. A Bodyshop owner would be pleased to know that the shop’s number, 2639-7467, corresponds to “BODYSHOP”.

    Write a program that, given an eight-digit number, writes to a file every possible eight-letter word combination corresponding to that number. There are 6561 (38) such words. Avoid phone numbers with the digits 0 and 1.

    Digit Letters
    2 A B C
    3 D E F
    4 G H I
    5 J K L
    6 M N O
    7 P R S
    8 T U V
    9 W X Y
    Table 1: Telephone keypad digits and letters.
    i've tried many ways.. but it is b'cos i don't have enough knowledge...please help please...

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    i've tried many ways.. but it is b'cos i don't have enough knowledge...please help please...
    Post a version that looks like you tried. We are helping people, we are not the homework assignment dumpster.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    8
    this is my program..tq... but i think i a bit away from the topic

  4. #4
    Registered User
    Join Date
    Sep 2005
    Posts
    8
    this is where i can go...hehe

  5. #5
    Information Crocodile
    Join Date
    Dec 2004
    Posts
    204
    I have already solved this problem a month ago. I got it from a programming contest site. Lemme look at my files.

  6. #6
    Information Crocodile
    Join Date
    Dec 2004
    Posts
    204
    This was a month ago. ( I have improved since then ( ashamed of this code ) )

    Its not exactly the same problem but the method should be the same. My solution was a little messy.

    Theres should be a better solution than mine. As this was made by a beginner .

    This code counts and prints all the possible combination of the last the four digits in a telephone number.

    Code:
    #include<stdio.h>
    #include<string.h>
    #include<ctype.h>
    #include<stdlib.h>
    #include<conio.h>
    
    #define A 65
    
    int main()
    {
    	char *icomb;
    	int intcomb[4] = { 0 };
    	char input[20] = { 0 };
    	int ctr1, ctr2, ctr3, ctr4;
    	int permutation = 0;
    	clrscr();
    
    	printf( "phone: " );
    	fgets( input, sizeof( input ), stdin );
    	icomb = strchr( input, '\n' );
    	icomb = NULL;
    	icomb = strchr( input, '-');
    	icomb = &icomb[1];
    	printf( "last 4 digit is %s", icomb );
    
    	for( ctr1 = 0; ctr1 < 3; ctr1++ ){
    		for( ctr2 = 0; ctr2 < 3; ctr2++ ){
    			for( ctr3 = 0; ctr3 < 3; ctr3++ ){
    				for( ctr4 = 0; ctr4 < 3; ctr4++ ){
    					printf( "\n%c%c%c%c",
    					  ((icomb[0]-48)<2?'0':(((icomb[0]-48)-2)*3)+A+ctr1+0),
    					  ((icomb[1]-48)<2?'0':(((icomb[1]-48)-2)*3)+A+ctr2+0),
    					  ((icomb[2]-48)<2?'0':(((icomb[2]-48)-2)*3)+A+ctr3+0),
    					  ((icomb[3]-48)<2?'0':(((icomb[3]-48)-2)*3)+A+ctr4+0));
    					 permutation++;
    					 if( icomb[3]-48 < 2 ) break;
    				}
    				if( icomb[2]-48 < 2 ) break;
    			}
    			if( icomb[1]-48 < 2 ) break;
    		}
    		if( icomb[0]-48 < 2 ) break;
    	}
    
    	printf( "\n\nTotal Permutation is %d", permutation );
    
    	getch();
    	return 0;
    }

  7. #7
    Registered User
    Join Date
    Sep 2005
    Posts
    8

    Talking

    thanx for the great code.... but i wan to know whether this code is all in C... only C is allowed in this code..... TQ

  8. #8
    Information Crocodile
    Join Date
    Dec 2004
    Posts
    204
    Yeah its in C. But why did you post this in C# forum?

    The code above isnt exactly the same. But itll give give you an idea on how to solve the problem.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  2. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  3. Recursion program trouble... ?
    By Beachblue in forum C Programming
    Replies: 7
    Last Post: 06-19-2008, 01:43 PM
  4. Trouble running a program Visual Studio
    By Swerve in forum C++ Programming
    Replies: 8
    Last Post: 03-03-2008, 11:15 AM