Return to the Top of Page, First Page, Novice Problem Set, or Veteran Problem Set.
The We-Got-It Answering Service has a novel idea. They take messages by entering them with a numeric keypad. Each letter or digit is entered as two digits. They are hiring you to write a program to decode the messages so that clients can read them.
Below is a chart of how each character is represented:
A 21 B 22 C 23
D 31 E 32 F 33
G 41 H 42 I 43
J 51 K 52 L 53
M 61 N 62 O 63
P 71 Q 72 R 73 S 74
T 81 U 82 V 83
W 91 X 92 Y 93 Z 94
0 00 1 01 2 02 3 03 4 04
5 05 6 06 7 07 8 08 9 09
. 11 ? 12 , 13 : 14 @ 15
" " 16 EOLN 17 EOM 18 EOF 19
NOTE: " " is a blank or space, EOLN means End Of LiNe, EOM means End Of Message, and EOF means End Of File.
As you can see, this chart allows them to translate most sentences into numbers. Your job is to read in a series of numbers and write out the original messages. Each message will end when you encounter an EOM. You stop processing when you encounter EOF.
Sample Input Data:
42
32
53
53
63
16
91
63
73
53
31
11
18
05
82
73
03
17
82
17
23
04
62
17
17
73
03
04
31
12
18
19
Sample Output:
Message 1:
HELLO WORLD.
Message 2:
5UR3
U
C4N
R34D?
NOTE: One blank line should separate each message in your output.
Return to the Top of Page, First Page, Novice Problem Set, or Veteran Problem Set.
Return to the Top of Page, First Page, Novice Problem Set, or Veteran Problem Set.
Source Code for a Solution to this Problem
// preprocessor directives #include <stdio.h> #define EOLN '\n' #define EOM '~' //typedefs typedef char STRING[100]; // prototypes void init(STRING values); int main(void) { int i = 1,j,ch,flag = 0; STRING values; //initialize values init(values); printf("Message %d:\n",i); scanf("%d",&ch); while( ch != 19) { if(1 == flag) { printf("Message %d:\n",++i); flag = 0; } //if if(EOM == values[ch]) { printf("\n\n"); flag = 1; } //if else printf("%c",values[ch]); scanf("%d",&ch); } //while return 0; } //main /* function values initializes the array of values */ void init(STRING values) { int i; for(i = 0; i < 100; i++) values[i] = '%'; for(i = 0; i < 10; i++) values[i] = i + 48; values[21] = 'A'; values[22] = 'B'; values[23] = 'C'; values[31] = 'D'; values[32] = 'E'; values[33] = 'F'; values[41] = 'G'; values[42] = 'H'; values[43] = 'I'; values[51] = 'J'; values[52] = 'K'; values[53] = 'L'; values[61] = 'M'; values[62] = 'N'; values[63] = 'O'; values[71] = 'P'; values[72] = 'Q'; values[73] = 'R'; values[74] = 'S'; values[81] = 'T'; values[82] = 'U'; values[83] = 'V'; values[91] = 'W'; values[92] = 'X'; values[93] = 'Y'; values[94] = 'Z'; values[11] = '.'; values[12] = '?'; values[13] = ','; values[14] = ':'; values[15] = '@'; values[16] = ' '; values[17] = '\n'; values[18] = '~'; return; }//end of init
Return to the Top of Page, First Page, Novice Problem Set, or Veteran Problem Set.
42 32 53 53 63 16 91 63 73 53 31 11 18 05 82 73 03 17 82 17 23 04 62 17 17 73 03 04 31 12 18 19
Return to the Top of Page, First Page, Novice Problem Set, or Veteran Problem Set.
Message 1: HELLO WORLD. Message 2: 5UR3 U C4N R34D?
Return to the Top of Page, First Page, Novice Problem Set, or Veteran Problem Set.
42 32 53 53 63 16 91 63 73 53 31 11 18 5 82 73 3 16 82 16 23 4 62 16 73 3 4 31 12 18 61 32 62 16 43 62 16 22 53 21 23 52 17 74 81 21 73 74 16 21 53 43 32 62 74 18 91 63 63 33 32 73 16 43 74 16 21 16 22 53 21 23 52 16 31 63 41 11 18 19
Return to the Top of Page, First Page, Novice Problem Set, or Veteran Problem Set.
Message 1: HELLO WORLD. Message 2: 5UR3 U C4N R34D? Message 3: MEN IN BLACK STARS ALIENS Message 4: WOOFER IS A BLACK DOG.
Return to the Top of Page, First Page, Novice Problem Set, or Veteran Problem Set.
01 09 09 09 16 53 74 82 16 42 43 41 42 16 74 23 42 63 63 53 16 71 73 63 41 73 21 61 61 43 62 41 16 23 63 62 81 32 74 81 18 18 61 21 93 16 81 42 32 16 33 63 73 23 32 16 22 32 16 91 43 81 42 16 93 63 82 18 91 32 16 21 73 32 16 53 21 22 16 61 43 23 32 16 22 32 62 81 17 63 62 16 91 63 73 53 31 16 31 63 61 43 62 21 81 43 63 62 12 18 52 81 73 21 92 53 32 73 15 53 74 82 11 32 31 82 18 19
Return to the Top of Page, First Page, Novice Problem Set, or Veteran Problem Set.
Message 1: 1999 LSU HIGH SCHOOL PROGRAMMING CONTEST Message 2: Message 3: MAY THE FORCE BE WITH YOU Message 4: WE ARE LAB MICE BENT ON WORLD DOMINATION? Message 5: KTRAXLER@LSU.EDU
Return to the Top of Page, First Page, Novice Problem Set, or Veteran Problem Set.
Return to the LSU High School Programming Contest Homepage