Time Limit (Common/Java): 1000 MS/3000 MS Memory Limit: 65536 KByte
Total Submit: 57 Accepted: 23
Description
Mirko received ed a message from his friend Slavko. slavko, being a world class cryptologist, likes to encrypt messages he sends to Mirko. this time, he decided to use One Time Pad encryption. OTP is impenetrable if used correctly, and Slavko knows this. he however, doesn' t want Mirko to bang his head on an impossible task, so he sent a few hints along with his message.
Mirko knows that Slavkos original plaintext contained only small letters of the English alphabet ('A'-'Z'), full stop '. and space ''(ASCII 3210 ). also, he knows that Slavko used only digits '0' to '9' as his key. after much thought, he realized he can determine locations of all spaces and full stops in the plaintext. he now asked you to write a program that will do so automatically.
From his previous dealings with Slavko, Mirko knows how OTP encryption works. let's look at a simple example. suppose you want to encode the string "abc efg" using "0120123" as key.
First, you transform both the key and plaintext into hexadecimal numbers using ASCII encoding. Then you align them and preform XOR operation on each pair. The resulting sequence is the encrypted message.
Input
The first line of input contains one integer N (1 ≤ N ≤1000), number of characters in the encrypted message.
Next line contains N integers, written in hexadecimal, larger than or equal to 010 and smaller than or equal to 12710, the encrypted message.
Output
The first and only line of output shoshould contain N characters, each representing one character in the plaintext. if the ith character of plaintext is a letter, the ith character of output shocould be a dash '-', if not, you shocould output a full stop '. '.
Sample Input
7
51 53 51 10 54 54 54
Sample Output
---.---
Source
TOJ
# Include <iostream> # include <cstdio> # include <vector> # include <cstring> # include <algorithm> # include <cstdlib> # include <set> using namespace std; set <int> S; int n; void init () {S. clear (); int tmp; char str [2] = {'. ', ''}; for (int I = 0; I <2; I ++) {for (int j = '0'; j <= '9 '; j ++) {tmp = str [I] ^ j; S. insert (tmp) ;}} int main () {init (); int I, tmp; while (scanf ("% d", & n )! = EOF) {for (I = 1; I <= n; I ++) {cin> hex> tmp; // hex considers ~ F set <int >:: iterator it; it = S. find (tmp); if (it = S. end () {// find it; printf ("-");} else {printf (". ") ;}} printf (" \ n ") ;}return 0 ;}