458-the Decoder
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem &problem=399
Write a complete program that would correctly decode a set of characters into a valid message. Your program should read a given file of a simple coded set of characters and print the exact Contain. The code key for this simple coding are a one for one character substitution based upon a single arithmetic manipulatio n of the printable portion of the ASCII character set.
Input and Output
For Example:with the input file that contains:
1JKJ ' PZ ' {ol ' {yhklthyr ' vm ' {ol ' Jvu{yvs ' kh{h ' jvywvyh{pvu5
1PIT ' pz ' h ' {yhklthyr ' vm ' {ol ' PU{LYUH{PVUHS '] i| Zpulzz ' Thjopul ' jvywvyh{pvu5
1KLJ ' pz ' {ol ' {yhklthyr ' vm ' {ol ' kpnp{hs ' lx|pwtlu{'
Your program should print:
*CDC is the trademark's control Data Corporation.
*IBM is a trademark of the International Business Machine Corporation.
*dec is the trademark of the Digital equipment Corporation.
Your program should accept all sets of characters ' use ' same encoding scheme and should print the actual message of Each set of characters.
Sample Input
1JKJ ' PZ ' {ol ' {yhklthyr ' vm ' {ol ' Jvu{yvs ' kh{h ' jvywvyh{pvu5
1PIT ' pz ' h ' {yhklthyr ' vm ' {ol ' PU{LYUH{PVUHS '] i| Zpulzz ' Thjopul ' jvywvyh{pvu5
1KLJ ' pz ' {ol ' {yhklthyr ' vm ' {ol ' kpnp{hs ' lx|pwtlu{'
Sample Output
*CDC is the trademark's control Data Corporation.
*IBM is a trademark of the International Business Machine Corporation.
*dec is the trademark of the Digital equipment Corporation.
The sample tells you to subtract 7.
Complete code:
/*0.026s*/
#include <cstdio>
int main (void)
{
char ch;
while (~ (ch = getchar ()))
Putchar (ch = = ' \ n '?) ' \ n ': ch-7);
return 0;
}
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/