JOJ 1240 The Decoder
2011-10-26 18:47
309 查看
Write a complete program that will 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 message that the characters contain. The code key for this simple coding
is a one for one character substitution based upon a single arithmetic manipulation 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{'Jvywvyh{pvu5
your program should print the message:
*CDC is the trademark of the 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 that use the 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{'Jvywvyh{pvu5
Sample Output
*CDC is the trademark of the Control Data Corporation.
*IBM is a trademark of the International Business Machine Corporation.
*DEC is the trademark of the Digital Equipment Corporation.
Answer
#include<iostream>
using namespace std;
int main()
{
char s[10000];
int i;
while( gets(s) )
{
for(i=0;i<strlen(s);i++)
if( int(s[i])-7<32 )
cout<<char( int(s[i]) +88 );
// ASCII有效字符位33-127
else
cout<<char( int(s[i]) -7 );
cout<<endl;
}
return 0;
}
is a one for one character substitution based upon a single arithmetic manipulation 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{'Jvywvyh{pvu5
your program should print the message:
*CDC is the trademark of the 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 that use the 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{'Jvywvyh{pvu5
Sample Output
*CDC is the trademark of the Control Data Corporation.
*IBM is a trademark of the International Business Machine Corporation.
*DEC is the trademark of the Digital Equipment Corporation.
Answer
#include<iostream>
using namespace std;
int main()
{
char s[10000];
int i;
while( gets(s) )
{
for(i=0;i<strlen(s);i++)
if( int(s[i])-7<32 )
cout<<char( int(s[i]) +88 );
// ASCII有效字符位33-127
else
cout<<char( int(s[i]) -7 );
cout<<endl;
}
return 0;
}
相关文章推荐
- joj1240
- JOJ 1002 Stockbroker Grapevine
- JOJ 1903 1129 1157 1278
- JOJ 1065: Truck Driver 解题报告
- joj 1107: Factorial
- ZOJ 1240
- ZOJ_1240
- joj 1989 Vampire Numbers
- joj 1386解题报告
- joj 1173
- joj 2736: 二叉树计数 卡特兰数取模 1<=n<=10^9,1<=m<=32768
- JOJ 1170: Wire Is So Expensive (MST kruskal 无合并)
- joj 2526
- joj2484
- joj 1131 Intersection
- joj2252
- joj2529
- joj 1171
- joj 2651
- joj 1195