Substitution Cypher/替换加密字符串 - ACM
2013-05-27 00:49
267 查看
Substitution Cypher
Time Limit: 1.0 Seconds Memory Limit: 65536K 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
zyxwvutsrqponmlkjihgfedcba
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
zyxwvutsrqponmlkjihgfedcba
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 mvd 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 hxsvwfovw uli 3 slfih
zugvi gsv hvxlmw CSC kiltiznnrmt xlmgvhg vmwh (mlg gl nvmgrlm,
drgsrm vzhb dzoprmt wrhgzmxv)!
题目意思:
第一行:密文字符串
第二行:待加密的字符串
第三行:<==第二行>
第四行:<==第一行>
后续行:待加密的文本
每行最多64个字符(加上回车)
第二行按理说应该和第一行长度相等,一一对应
解题方法:
在<待加密的文本>中, 如果在<待加密的字符串>数组中找到了该字符,则
用<待加密的字符串>对应的<密文字符串>替换即可.
测试截图:
女孩不哭 @ 2013-05-27 00:47:49 @ http://www.cnblogs.com/nbsofer
Time Limit: 1.0 Seconds Memory Limit: 65536K 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
zyxwvutsrqponmlkjihgfedcba
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
zyxwvutsrqponmlkjihgfedcba
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 mvd 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 hxsvwfovw uli 3 slfih
zugvi gsv hvxlmw CSC kiltiznnrmt xlmgvhg vmwh (mlg gl nvmgrlm,
drgsrm vzhb dzoprmt wrhgzmxv)!
题目意思:
第一行:密文字符串
第二行:待加密的字符串
第三行:<==第二行>
第四行:<==第一行>
后续行:待加密的文本
每行最多64个字符(加上回车)
第二行按理说应该和第一行长度相等,一一对应
解题方法:
在<待加密的文本>中, 如果在<待加密的字符串>数组中找到了该字符,则
用<待加密的字符串>对应的<密文字符串>替换即可.
#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(b); puts(a); len_a = strlen(a); 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; }
测试截图:
女孩不哭 @ 2013-05-27 00:47:49 @ http://www.cnblogs.com/nbsofer
相关文章推荐
- [2012山东ACM省赛] n a^o7 !(模拟,字符替换)
- [2012山东ACM省赛] n a^o7 !(模拟,字符替换)
- C# 用正则表达式替换字符串中所有特殊字符
- NSString:创建,长度,取字符,是否以某字符串开头,结尾, 查找指定字符串的范围,截取,拼接,替换,比较,替换,数值转换,大小写转换
- java中替换字符以及回车换行
- shell中使用sed替换指定位置的字符
- Perl 字符替换操作-用于两个文件的合并
- Linux替换字符命令
- shell中vi替换特殊字符(制表符\t等)的方法
- 替换^M字符
- VC编辑器输入字符会替换掉原来字符解决方法
- UE如何将某些字符替换成换行
- C#正则表达式替换特殊字符
- 2016去哪儿编程题:字符替换
- 控制字符长度样式(超过部分用“...”替换)
- R: 字符查询匹配和替换 grep(...) - Pattern Matching and Replacement
- HDU 5578.Friendship of Frog【字符串相同字符最近距离】【2015ACM/ICPC亚洲区上海站】【12月30】
- JAVA insert() 插入字符串 reverse() 颠倒 delete()和deleteCharAt() 删除字符 replace() 替换 substring() 截取子串
- [BZOJ1031][JSOI2007]字符加密Cipher && 后缀数组
- Dreamweaver里使用正则表达式替换字符