第十周项目二 M$pszi$y是嘛意思?

来源:互联网 发布:淘宝买的dnf搬砖号 编辑:程序博客网 时间:2024/05/19 14:54

故事引入:小明给小丽传纸条,上面写着M$pszi$y,设计程序破解这串字符

——————————————————————

问题及代码:

#include <cstdio>using namespace std;int main(){    char ch;    while((ch=getchar())!='\n')    {        putchar (ch-4);    }    return 0;}

运行结果:



——————————————————————

故事继续:由于他们的传密码方式被破解,两人决定给这串字符用数字加密,输入正确的密码后才知道字符所表示的含义。

——————————————————————

问题及代码:

#include <cstdio>#include <iostream>using namespace std;int main(){    int a;    char ch;    cout<<"加密数字为:";    cin>>a;    ch=getchar();    while((ch=getchar())!='\n')    {        putchar (ch-a);    }    return 0;}

运行结果(图为输入了错误的数字密码6,正确应该为4):



0 0
原创粉丝点击