Substitution cypher/replace encrypted string-ACM

Source: Internet
Author: User

Substitution cypher

Time Limit: 1.0 seconds memory limit: 65536 K multiple test files

Substitution cyphers are the simplest of cyphers where the letters of one
Alphabet are substituted for the letters of another alphabet. In one form or
Another, they 've been in use for over 2000 years.

input
A line containing the plaintext alphabet
A line containing the substitution alphabet
several lines of text

output
A line containing the substitution alphabet
A line containing the plaintext alphabet
the converted lines of text

Please note:
all lines will be at most 64 characters, plus a trailing end-of-line
character. pass through all characters not found in the plaintext alphabet.

sample input
abcdefghijklmnopqrstuvwxyz
birthday
Shar's birthday:
the birthday is October 6th, but the party will be Saturday,
October 5. it's my 24th birthday and the first one in some
years for which I 've been employed. plus, I have new clothes.
so I have cause to celebrate. more importantly, though,
we 've cleaned the house! The address is 506-d Albert Street.
extra enticement for CS geeks: There are several systems in
the house, and the party is conveniently scheduled for 3 hours
after the second CSC programming contest ends (not to mention,
within easy walking distance )!

sample output
average
abcdefghijklmnopqrstuvwxyz
sszi' H brigswzb:
TSV yrigswzb RH oxglyvi 6gs, yfg GSV kzigb droo YV szgfiwzb,
oxglyvi 5. IG 'H Nb 24gs yrigswzb zmw GSV urihg lmv rm hlnv
bvzih Uli dsrxs I 'ev yvvm vnkolbvw. pofh, I szev 3d-xolgsvh.
sl I szev xzfhv GL xvovyizgv. mliv rnkligzmgob, gslfts,
DV 'ev xovzmvw GSV slfhv! TSV zwwivhh RH 506-d aoyvig sgivvg.
ecgiz vmgrxvnvmg Uli CS tvvph: gsviv Ziv hvevizo hbhgvnh Rm
GSV slfhv, zmw GSV kzigb RH xlmevmrvmgob Uli 3 slfih
zugvi GSV hvxlmw CSC kiltiznnrmt xlmgvhg vmwh (mlg gl nvmgrlm,
drgsrm vzhb dzoprmt wrhgzmxv )!

Question meaning:
Line 1: ciphertext string
Row 2: string to be encrypted
Row 3: <= Row 2>
Row 4: <= The first line>
Subsequent lines: Text to be encrypted

Each line can contain up to 64 characters (with a carriage return)
The second line should be equal to the first line in length, one-to-one correspondence

Solution:
In <text to be encrypted>, if this character is found in the <string to be encrypted> array
Replace the <ciphertext string> with the <ciphertext string>.

# Include <stdio. h> # Include < String . H> Int Main ( Void  ){  Char A [ 64 ];  Char B [ 64  ];  Char S [ 64  ];  Int  I, j, Len, len_a; gets (a); gets (B); puts (a); len_a = Strlen ();  While  (Gets (s) {Len = Strlen (s );  For (I =0 ; I <Len; I ++ ){  For (J = 0 ; J <len_a; j ++ ){  If (S [I] = A [J]) {printf (  "  % C  "  , B [J]);  Break  ;}}  If (J =Len_a) {printf (  "  % C  "  , S [I]) ;}} printf (  "  \ N  "  );}  Return   0  ;} 

Test:

Girl don't cry @ 00:47:49 @ http://www.cnblogs.com/nbsofer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.