ZOJ 1042 W’s Cipher
题目大意:按照规则解码。26个字母分成三组,每一组按照顺时针移位编码。现在已知移动的位数,要求解码。
解法:以前看过一本古典密码学的书,百度贴吧密码吧也有很多经典的加密方法,想什么凯撒移位、弗吉尼亚编码等等。古典密码学比现代密码学有趣多了。这道题可以开三个队列,先把字符串压入对应的队列,然后调整顺序,再合成输出。不难,稍烦。
参考代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std; int main(){
int k1,k2,k3,i,len,pos[100];
char str[100],c;
queue<char> s1;
queue<char> s2;
queue<char> s3; while(cin>>k1>>k2>>k3){
if(k1==0&&k2==0&&k3==0)break;
scanf("%s",&str);
while(!s1.empty())s1.pop(); //empty queues
while(!s2.empty())s2.pop();
while(!s3.empty())s3.pop();
len=strlen(str);
for(i=0;i<len;i++){
if(str[i]<='i'&&str[i]>='a'){
s1.push(str[i]);
pos[i]=1;
}
else if(str[i]<='r'&&str[i]>='j'){
s2.push(str[i]);
pos[i]=2;
}
else{
s3.push(str[i]);
pos[i]=3;
}
}
if(!s1.empty())k1=k1%(s1.size()); // if s1 is empyt, k1%(s1.seze()) will cause floating point error
if(!s2.empty())k2=k2%(s2.size());
if(!s3.empty())k3=k3%(s3.size());
while(k1<s1.size()){
c=s1.front();
s1.pop();
s1.push(c);
k1++;
}
while(k2<s2.size()){
c=s2.front();
s2.pop();
s2.push(c);
k2++;
}
while(k3<s3.size()){
c=s3.front();
s3.pop();
s3.push(c);
k3++;
}
for(i=0;i<len;i++){
switch(pos[i]){
case 1:
cout<<s1.front();
s1.pop();
break;
case 2:
cout<<s2.front();
s2.pop();
break;
case 3:
cout<<s3.front();
s3.pop();
break;
}
}
cout<<endl;
} return 0;
}
ZOJ 1042 W’s Cipher的更多相关文章
- POJ - 1107 W's Cipher
POJ - 1107 W's Cipher Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d & %I64u De ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- PHP的AES加密类
PHP的AES加密类 aes.php <?php /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ...
- ethereumjs/ethereumjs-wallet
Utilities for handling Ethereum keys ethereumjs-wallet A lightweight wallet implementation. At the m ...
- lucene入门创建索引——(二)
1.程序宏观结构图
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3494 BCD Code(AC自动机+数位DP)
BCD Code Time Limit: 5 Seconds Memory Limit: 65536 KB Binary-coded decimal (BCD) is an encoding ...
随机推荐
- mysql的binlog
mysql> show global variables like '%bin%'; +---------------------------------+------------------- ...
- php 判断是否 是手机访问
//判断是否属手机 function is_mobile() { $user_agent = $_SERVER['HTTP_USER_AGENT']; $mobile_agents = Array(& ...
- IT公司100题-15-求二元查找树的镜像
问题描述: 输入一颗二元查找树,将该树转换为它的镜像树,即对每一个节点,互换左右子树. 例如输入: 6/ \4 12/ \ / \2 5 8 16 输出: 6/ ...
- UITableViewCell Property “icon” cannot be found in forward class object “DJWeiBo”
UITableViewCell 自定义表格 实体属性不显示错误 Property “icon” cannot be found in forward class object “DJWeiBo”引入实 ...
- matlab函数调用及数据传递
http://www.cnblogs.com/duanp/archive/2008/11/29/Matlab-GUIDE.html函数调用 在一个m文件中,可以定义多个函数,但是文件名一定要与第一个函 ...
- KVO的内部实现原理
kvo概述 kvo,全称Key-Value Observing,它提供了一种方法,当对象某个属性发生改变时,允许监听该属性值变化的对象可以接受到通知,然后通过kvo的方法响应一些操作. kvo实现原理 ...
- 破解Xamarin
试用了一阵子Mono For Android,今天到期了,,囊中羞涩,只好破解. 说是要在vs2013的英文界面下运行破解包,不知道是真是假,下载并安装了一个. 然后又下载了破解包.是个名为xa.ra ...
- php的预定义数组
PHP预定义变量数组 1.$_SERVER 变量由Web服务器设定或者直接与当前的脚本的执行环境相关联 $_SERVER超级全局变量包含由web服务器创建的信息,它提供了服务器和客户配置及当前请求环境 ...
- IIS 发布后文件拒绝访问
今天遇到一个很小的问题,代码中写XML文件,本地运行没有问题,一发布到服务器上就出现 代码如下: XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load ...
- Best Practice: Avoiding or minimizing synchronization in servlets
Introduction Minimize the use of synchronization in servlets. Because servlets are multi-threaded, s ...