字符串加密解密变换 问题

写在前面:

经常会遇到那种给一个字符串,然后按照对应的变换规则,将相应的字符进行一些变换,如不同种类的键盘,或者是加密解密的编码规则等等。

 


正文:

对于这种问题,一般有两种解体思路:

第一种就是按照题目中给的条件,将字符变换的规律找出,然后可以直接遍历转换

 

第二种也就是如果是实在没有规律那就打个表解决一下

建立两个字符数组(字符串)A1,A2 ; 一个代表原来的字符序列,另一个表示转换后的字符序列,然后在将字符A1中找到相应的位置,直接在A2中进行一系列的转换即可。

 

样例:ZOJ - 3878

Convert QWERTY to Dvorak


Time Limit: 2 Seconds      Memory Limit: 65536 KB


Edward, a poor copy typist, is a user of the Dvorak Layout. But now he has only a QWERTY Keyboard with a broken Caps Lock key, so Edward never presses the broken Caps Lock key. Luckily, all the other keys on the QWERTY keyboard work well. Every day, he has a lot of documents to type. Thus he needs a converter to translate QWERTY into Dvorak. Can you help him?

The QWERTY Layout and the Dvorak Layout are in the following:

Qwerty Layout
The QWERTY Layout

Dvorak Layout
The Dvorak Layout

Input

A QWERTY document Edward typed. The document has no more than 100 kibibytes. And there are no invalid characters in the document.

Output

The Dvorak document.

Sample Input

Jgw Gqm Andpw a H.soav Patsfk f;doe
Nfk Gq.d slpt a X,dokt vdtnsaohe
Kjd yspps,glu pgld; aod yso kd;kgluZ
1234567890
`~!@#$%^&*()}"']_+-=ZQqWEwe{[\|
ANIHDYf.,bt/
ABCDEFuvwxyz

Sample Output

Hi, I'm Abel, a Dvorak Layout user.
But I've only a Qwerty keyboard.
The following lines are for testing:
1234567890
`~!@#$%^&*()+_-={}[]:"'<>,.?/\|
ABCDEFuvwxyz
AXJE>Ugk,qf;

 

题解: 

#include<bits/stdc++.h>
using namespace std;
char s1[]= {"-=_+qwertyuiop[]QWERTYUIOP{}asdfghjkl;'ASDFGHJKL:\"zxcvbnm,./ZXCVBNM<>?"};
char s2[]= {"[]{}',.pyfgcrl/=\"<>PYFGCRL?+aoeuidhtns-AOEUIDHTNS_;qjkxbmwvz:QJKXBMWVZ"};
char print(char c)
{
    for(int i=0; s1[i]; i++)
        if(s1[i]==c)
            return s2[i];
    return c;
}
int main()
{
	char c;
    while (scanf("%c",&c)!=EOF)
      printf("%c",print(c));
    return 0;
}

注意:: 可以直接在输入时按照一个一个字符输入,并进行转换,可以节约空间复杂度和时间复杂度

  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

12 26 25

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值