CDOJ 1270 Playfair
模拟题,代码写得比较乱。。。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std; char s[];
char tmp[];
char u[];
char Map[][];
bool flag[]; vector<int> ans;
int tot; void f()
{
tot = ;
for (int i = ; s[i]; i++){
if (s[i] >= 'a'&&s[i] <= 'z')
tmp[tot++] = s[i];
else if (s[i] >= 'A'&&s[i] <= 'Z')
tmp[tot++] = s[i] - 'A' + 'a';
} tmp[tot] = ;
for (int i = ; tmp[i]; i++)
if (tmp[i] == 'j') tmp[i] = 'i';
} void EYET()
{
for (int i = ; s[i]; i++){
if (s[i] >= 'a'&&s[i] <= 'z')
tmp[tot++] = s[i];
else if (s[i] >= 'A'&&s[i] <= 'Z')
tmp[tot++] = s[i] - 'A' + 'a';
} tmp[tot] = ;
for (int i = ; tmp[i]; i++)
if (tmp[i] == 'j') tmp[i] = 'i';
} void Fill()
{
tot = ;
memset(Map, , sizeof Map);
memset(flag, , sizeof flag);
for (int i = ; tmp[i]; i++)
{
// printf("%c %d \n", tmp[i], flag[tmp[i] - 'a']);
if (flag[tmp[i] - 'a'] == )
{
flag[tmp[i] - 'a'] = ; tot++;
int r, c;
if (tot % == ) r = tot / ;
else r = tot / + ;
c = tot % ;
if (c == ) c = ;
Map[r][c] = tmp[i];
}
} for (int i = ; i<; i++)
{
char sign = i + 'a';
if (sign == 'j') continue;
if (flag[i] == ) continue; tot++;
int r, c;
if (tot % == ) r = tot / ;
else r = tot / + ;
c = tot % ;
if (c == ) c = ;
Map[r][c] = sign;
}
} bool P1(char a, char b)
{ int posxA, posyA; int posxB, posyB;
for (int i = ; i <= ; i++)
{
for (int j = ; j <= ; j++)
{
if (Map[i][j] == a) posxA = i, posyA = j;
if (Map[i][j] == b) posxB = i, posyB = j;
}
} if (posxA == posxB)
{
posyA++;
if (posyA > ) posyA = ; posyB++;
if (posyB > ) posyB = ; ans.push_back(Map[posxA][posyA] - 'a');
ans.push_back(Map[posxB][posyB] - 'a'); return ;
}
return ;
} bool P2(char a, char b)
{ int posxA, posyA; int posxB, posyB;
for (int i = ; i <= ; i++)
{
for (int j = ; j <= ; j++)
{
if (Map[i][j] == a) posxA = i, posyA = j;
if (Map[i][j] == b) posxB = i, posyB = j;
}
} if (posyA == posyB)
{
posxA++;
if (posxA > ) posxA = ; posxB++;
if (posxB > ) posxB = ; ans.push_back(Map[posxA][posyA] - 'a');
ans.push_back(Map[posxB][posyB] - 'a'); return ;
}
return ;
} void P3(char a, char b)
{
int posxA, posyA; int posxB, posyB; for (int i = ; i <= ; i++)
{
for (int j = ; j <= ; j++)
{
if (Map[i][j] == a) { posxA = i, posyA = j; }
if (Map[i][j] == b) { posxB = i, posyB = j; }
}
} ans.push_back(Map[posxA][posyB] - 'a');
ans.push_back(Map[posxB][posyA] - 'a');
} void work()
{
int len = strlen(tmp);
strcpy(u, tmp); queue<int>Q;
for (int i = ; i < len; i++) Q.push(tmp[i]-'a'); while (!Q.empty())
{
char sign1 = Q.front() + 'a';
char sign2;
Q.pop();
if (Q.empty()) break;
if (Q.front()+'a' == sign1)
{
sign2 = 'x';
if (P1(sign1, sign2) == ) continue;
else if (P2(sign1, sign2) == ) continue;
else P3(sign1, sign2);
}
else
{
sign2 = Q.front() + 'a';
Q.pop();
if (P1(sign1, sign2) == ) continue;
else if (P2(sign1, sign2) == ) continue;
else P3(sign1, sign2);
}
}
} int main()
{
while (gets(s))
{
ans.clear();
f();
Fill(); bool Exit = ; tot = ;
while ()
{
scanf("%s", s);
int len = strlen(s);
if (s[] == '*' || s[len - ] == '*') Exit = ;
EYET();
if (Exit) break;
}tmp[tot] = ;
work();
for (int i = ; i < ans.size(); i++) printf("%c", ans[i] + 'a');
printf("\n");getchar();
}
return ;
}
CDOJ 1270 Playfair的更多相关文章
- CDOJ 1270 Playfair(模拟)
题目链接 Playfair is a kind of substitution cipher.And the encryption role is simple.In general,there ar ...
- 信息安全-1:python之playfair密码算法详解[原创]
转发注明出处: http://www.cnblogs.com/0zcl/p/6105825.html 一.基本概念 古典密码是基于字符替换的密码.加密技术有:Caesar(恺撒)密码.Vigenere ...
- poj 1270(toposort)
http://poj.org/problem?id=1270 题意:给一个字符串,然后再给你一些规则,要你把所有的情况都按照字典序进行输出. 思路:很明显这肯定要用到拓扑排序,当然看到discuss里 ...
- cdoj 1489 老司机采花
地址:http://acm.uestc.edu.cn/#/problem/show/1489 题目: 老司机采花 Time Limit: 3000/1000MS (Java/Others) M ...
- hiho #1361 Playfair密码表
题目1 : Playfair密码表 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho经常用Playfair密码表加密自己的代码. 密码表是按以下步骤生成的. ...
- python playfair
#########################Playfair密码######################### #约定1:若明文字母数量为奇数,在明文末尾添加一个'Z' #约定2:'I'作为 ...
- 【BZOJ】1270: [BeijingWc2008]雷涛的小猫(DP+水题)
http://www.lydsy.com/JudgeOnline/problem.php?id=1270 这完全是一眼题啊,但是n^2的时间挺感人.(n^2一下的级别请大神们赐教,我还没学多少dp优化 ...
- hdu 1270 小希的数表
思路:一定有sum[1]=num[1]+num[2],sum[2]=num[1]+num[3]; 但是sum[3]不知道是由num[1]+num[4]还是num[2]+num[3],这就需要枚举一下了 ...
- BZOJ 1270: [BeijingWc2008]雷涛的小猫( dp )
简单的dp.. dp(i,j) = max(dp(x,y))+cnt[i][j], (x,y)->(i,j)是合法路径. 设f(i)= max(dp(x,y))(1≤x≤N, 1≤y≤i), g ...
随机推荐
- make TARGET_PRODUCT=am335xevm OMAPES=4.x rowboat_clean 出现sgx相关的错误
这些错误是一些链接错误,由于地址变更导致的软链接不对.所以只要更改下软链接的具体地址就可以.
- Java 类的加载过程(阿里面试题)
问以下程序打印出什么内容: 问题及解析如下: /** * 加载方法不等于执行方法,初始化变量则会赋值 * 类加载顺序应为 加载静态方法-初始化静态变量-执行静态代码块 * 实例化时 先加载非静态方法- ...
- c语言的编译过程和GCC 编译参数
原文: http://www.cnblogs.com/zhangShanGui/p/4912135.html C语言的编译过程和GCC编译参数 C语言的编译一般有三个步骤: 预编译: gcc -E - ...
- Redis 笔记
Redis是一个key-value存储系统.和Memcached类似,但是解决了断电后数据完全丢失的情况,而且她支持更多无化的value类型,除了和string外,还支持lists(链表).sets( ...
- UVA - 10635 最长公共子序列
input n,p,q 2<=n<=250 1<=p,q<=n*n 1 a1 a2 a3 ... ap 1<ai<n*n,ai!=aj 1 b1 b2 b3 ... ...
- ssh登录nat模式的VMware虚拟机
有时候本地PC是固定IP上网方式且无多余IP,而我们又希望使用putty登陆VMware中的虚拟机且虚拟机可以上外网,那么这时候就可以使用端口映射. 1.本地环境简述 本地PC IP:192.168. ...
- python 第三章 字符串-例1
1.字段宽度和精度 >>>'%.*s' % (10,'Gruido') ' Guido' >>>'%.-*s' % (10,'Gruido') 'Guido ...
- SQL Server触发器的禁用和启用
禁用: ALTER TABLE trig_example DISABLE TRIGGER trig1 GO 恢复: ALTER TABLE trig_example ENABLE TRIGGER tr ...
- UVALive 2147 Push!!(队列实现DP)
就我的理解来说这个题,本质上是一个DP题,不应该说是搜索,因为我的做法是把表格中所有的数据都找到,使用队列暴力来遍历出所有状态,因为题目中的数据范围小,所有耗时也小. 首先分析箱子是一个被动物体,人是 ...
- Amoeba for MySQL
Amoeba for MySQL Amoeba for MySQL致力于MySQL的分布式数据库前端代理层,它主要在应用层访问MySQL的时候充当query 路由功能,专注 分布式数据库 proxy ...