[模拟]解密QQ号

题目描述

新学期开始了,小哈是小哼的新同,小哼向小哈询问QQ号,小哈当然不会直接告诉小哼。所以小哈给了小哼一串加密过的数字,同时小哈也告诉了小哼解密规则。规则是这样的:首先将第1个数删除,紧接着将第2个数放到这串数的末尾,再将第3个数删除并将第4个数再放到这串数的末尾,再将第5个数删除……直到剩下最后一个数,将最后一个数也删除。按照刚才删除的顺序,把这些删除的数连在一起就是小哈的QQ啦。现在你来帮帮小哼吧。小哈给小哼加密过的一串数是“6 3 1 7 5 8 9 2 4”。解密后小哈的QQ号应该是“6 1 5 9 4 7 2 8 3”。

这题没什么好讲的,主要是第一次尝试用类写题目记录一下

/*
Author  : yukki
Time    : 2020.9.12
OJ      : aoj
Pid     : 1852
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define  F1(i,n) for(i=1;i<=n;i++)
#define  F0(i,n) for(i=0;i<=n;i++)
#define _F1(i,n) for(i=n;i>=1;i--)
#define _F0(i,n) for(i=n;i>=0;i--)
int n,m;
class QQ
{
    public:
        queue <int> del;
        queue <int> num;

    void Add(int x)
    {
        num.push(x);
    }

    void Delete()
    {
        int x = num.front();
        del.push(x);
        num.pop();
    }

    void Add_tail()
    {
        int x = num.front();
        num.pop();
        num.push(x);
    }
    void print()
    {
        while(!del.empty())
        {
            cout<<del.front()<<" ";
            del.pop();
        }
    }
};
int main()
{
    register int i,j;
    int len;
    QQ qq;
    freopen("in","r",stdin);
    scanf("%d",&len);
    F1(i,len)
    {
        int tmp;
        scanf("%d",&tmp);
        qq.Add(tmp);
    }
    while(!qq.num.empty())
    {
        if(qq.num.size() == 1)
        {
            qq.Delete();
            continue;
        }
        qq.Delete();
        qq.Add_tail();
    }
    qq.print();
    cout<<endl;
    return 0;
}

在python中倒是用过几次类,感觉挺好玩的,多写写。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PGP(Pretty Good Privacy)是一种加密通信协议,用于保护数据的机密性和完整性。在PGP中,公钥加密算法用于加密解密数据。 以下是一个简单的PGP模拟公钥加解密的Python代码示例: ```python from Crypto.PublicKey import RSA from Crypto.Cipher import PKCS1_OAEP # 生成公钥和私钥 key = RSA.generate(2048) private_key = key.export_key() public_key = key.publickey().export_key() # 加密函数 def encrypt(public_key, plaintext): key = RSA.import_key(public_key) cipher_rsa = PKCS1_OAEP.new(key) ciphertext = cipher_rsa.encrypt(plaintext) return ciphertext # 解密函数 def decrypt(private_key, ciphertext): key = RSA.import_key(private_key) cipher_rsa = PKCS1_OAEP.new(key) plaintext = cipher_rsa.decrypt(ciphertext) return plaintext # 测试加解密 plaintext = b'Hello, world!' ciphertext = encrypt(public_key, plaintext) decrypted = decrypt(private_key, ciphertext) print(f"Plaintext: {plaintext}") print(f"Ciphertext: {ciphertext}") print(f"Decrypted: {decrypted}") ``` 在这个例子中,我们使用了Python加密库`pycryptodome`中的RSA加密算法和PKCS#1 OAEP填充方式。我们首先生成了一个2048位的RSA密钥对,并将公钥和私钥导出为字符串。然后定义了一个加密函数和一个解密函数,分别使用RSA加密算法和PKCS#1 OAEP填充方式进行加密解密。最后我们测试了加解密的功能,并打印出了结果。 需要注意的是,这只是一个简单的PGP模拟公钥加解密示例,实际使用PGP时还需要考虑密钥管理、数字签名等问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值