Newsgroups: comp.sources.misc From: friedenb@boswell.egr.msu.edu (Gedaliah Friedenberg) Subject: v36i111: phone-nums - C++ Anagram for Phone numbers, Part01/01 Message-ID: <1993Apr19.032148.13127@sparky.imd.sterling.com> Date: Mon, 19 Apr 1993 03:21:48 GMT Approved: kent@sparky.imd.sterling.com Submitted-by: friedenb@boswell.egr.msu.edu (Gedaliah Friedenberg) Posting-number: Volume 36, Issue 111 Archive-name: phone-nums/part01 Environment: C++ I saw a post looking for an angaram that takes phone numbers and outputs all the possible word combinations from it. I had a friend write this. I am posting it for him and take no credit for it. Ex. A University of Michigan fan might want a phone number 646-2583 (M GO BLUE) or a Michigan State fan might have 772-7816 (SPARTAN). This program will take your phone number and give you all of the possible word combinations. A 7 digit phone number was assumed. Since the numbers 1 and 0 have no letters associated with them, the program will leave in the 1 or the 0 in the word cominations. It was considered to put the program through a dictionary and only output the outcomes that are actual words. But, since a person might get a possible output of KSGKING (from a phone # of 574-5464) they might want to know that they have the phone number of 574-KING (maybe they are an Elvis fan ;^) My friend could not figure out a way to look for possible words within the output unless the word was the entire 7 letters. To use the program, just compile ('g++ phone-num.c -o phone-num') and type 'phone-num' to execute. Enter each of the phone numbers on a line by itself. Ex. 355-2088 would be 3 5 5 2 0 8 8 2,200 possibilities exist, so you might want to redirect the output to a file. Gedaliah Friedenberg -=-Department of Mechanical Engineering -=-Department of Metallurgy, Mechanics and Materials Science -=-Michigan State University ======================= #! /bin/sh # This is a shell archive. Remove anything before this line, then feed it # into a shell via "sh file" or similar. To overwrite existing files, # type "sh file -c". # Contents: README phone-nums.c # Wrapped by kent@sparky on Sun Apr 18 22:03:25 1993 PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH echo If this archive is complete, you will see the following message: echo ' "shar: End of archive 1 (of 1)."' if test -f 'README' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'README'\" else echo shar: Extracting \"'README'\" \(1449 characters\) sed "s/^X//" >'README' <<'END_OF_FILE' XI saw a post looking for an angaram that takes phone numbers and Xoutputs all the possible word combinations from it. I had a friend Xwrite this. I am posting it for him and take no credit for it. X XEx. A University of Michigan fan might want a phone number X646-2583 (M GO BLUE) or a Michigan State fan might have X772-7816 (SPARTAN). X XThis program will take your phone number and give you all of the possible Xword combinations. A 7 digit phone number was assumed. X XSince the numbers 1 and 0 have no letters associated with them, Xthe program will leave in the 1 or the 0 in the word cominations. X XIt was considered to put the program through a dictionary and only Xoutput the outcomes that are actual words. But, since a person might Xget a possible output of KSGKING (from a phone # of 574-5464) they Xmight want to know that they have the phone number of 574-KING (maybe Xthey are an Elvis fan ;^) My friend could not figure out a way to Xlook for possible words within the output unless the word was the entire X7 letters. X XTo use the program, just compile ('g++ phone-num.c -o phone-num') and type X'phone-num' to execute. Enter each of the phone numbers on a line by itself. XEx. 355-2088 would be X3 X5 X5 X2 X0 X8 X8 X X2,200 possibilities exist, so you might want to redirect the output to a Xfile. X XGedaliah Friedenberg X-=-Department of Mechanical Engineering X-=-Department of Metallurgy, Mechanics and Materials Science X-=-Michigan State University END_OF_FILE if test 1449 -ne `wc -c <'README'`; then echo shar: \"'README'\" unpacked with wrong size! fi # end of 'README' fi if test -f 'phone-nums.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'phone-nums.c'\" else echo shar: Extracting \"'phone-nums.c'\" \(1194 characters\) sed "s/^X//" >'phone-nums.c' <<'END_OF_FILE' X#include X#include X Xvoid main( void ) X X{ X X// PHONE LETTER to NUMBER possibility sorter. X X char button[35] = {"000111ABCDEFGHIJKLMNOPRSTUVWXY"} ; X char co[7]; X short number[10]; X int a=0; X X cout << "\n\nPlease type telephone number XX [seven times tota l]\n"; X X for( int i=0;i<7;i++ ) X { X cin >> number[i]; X } X X cout << "\n\nNow Working\n"; X X for( i=0;i<3;i++ ) X { X co[0]=button[((number[0])*3+i)]; X X for( int j=0;j<3;j++ ) X { X co[1]=button[((number[1])*3+j)]; X X for( int k=0;k<3;k++ ) X { X co[2]=button[((number[2])*3+k)];a++; X X for( int l=0;l<3;l++ ) X { X co[3]=button[((number[3])*3+l)];a++; X X for( int m=0;m<3;m++ ) X { X co[4]=button[((number[4])*3+m)];a++; X X for( int n=0;n<3;n++ ) X { X co[5]=button[((number[5])*3+n)];a++; X X for( int o=0;o<3;o++ ) X { X co[6]=button[((number[6])*3+o)];a++; X X for(int p=0; p<7; p++) // output letter combo X cout << co[p] ; X cout << '\n'; // issue newline X X } // ... X } // ... X } // ... X } // .... X } // .... X } // second letter X } // first letter X} // main END_OF_FILE if test 1194 -ne `wc -c <'phone-nums.c'`; then echo shar: \"'phone-nums.c'\" unpacked with wrong size! fi # end of 'phone-nums.c' fi echo shar: End of archive 1 \(of 1\). cp /dev/null ark1isdone MISSING="" for I in 1 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have the archive. rm -f ark[1-9]isdone else echo You still must unpack the following archives: echo " " ${MISSING} fi exit 0 exit 0 # Just in case...