模拟题,代码写得比较乱。。。

#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的更多相关文章

  1. CDOJ 1270 Playfair(模拟)

    题目链接 Playfair is a kind of substitution cipher.And the encryption role is simple.In general,there ar ...

  2. 信息安全-1:python之playfair密码算法详解[原创]

    转发注明出处: http://www.cnblogs.com/0zcl/p/6105825.html 一.基本概念 古典密码是基于字符替换的密码.加密技术有:Caesar(恺撒)密码.Vigenere ...

  3. poj 1270(toposort)

    http://poj.org/problem?id=1270 题意:给一个字符串,然后再给你一些规则,要你把所有的情况都按照字典序进行输出. 思路:很明显这肯定要用到拓扑排序,当然看到discuss里 ...

  4. cdoj 1489 老司机采花

    地址:http://acm.uestc.edu.cn/#/problem/show/1489 题目: 老司机采花 Time Limit: 3000/1000MS (Java/Others)     M ...

  5. hiho #1361 Playfair密码表

    题目1 : Playfair密码表 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho经常用Playfair密码表加密自己的代码. 密码表是按以下步骤生成的. ...

  6. python playfair

    #########################Playfair密码######################### #约定1:若明文字母数量为奇数,在明文末尾添加一个'Z' #约定2:'I'作为 ...

  7. 【BZOJ】1270: [BeijingWc2008]雷涛的小猫(DP+水题)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1270 这完全是一眼题啊,但是n^2的时间挺感人.(n^2一下的级别请大神们赐教,我还没学多少dp优化 ...

  8. hdu 1270 小希的数表

    思路:一定有sum[1]=num[1]+num[2],sum[2]=num[1]+num[3]; 但是sum[3]不知道是由num[1]+num[4]还是num[2]+num[3],这就需要枚举一下了 ...

  9. 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 ...

随机推荐

  1. wpf绑定之格式化日期

    只显示年月日: StringFormat='{}{0:yyyy/MM/dd}' 又或者: StringFormat='{}{0:yyyy年MM月dd日 dddd HH:mm:ss}',Converte ...

  2. thrift概述

    Apache Thrift 是FaceBook实现的一种跨平台的远程服务调用(RPC)的框架.它采用接口描述语言(IDL)定义并创建服务,传输数据采用二进制格式,相对于XML和Json等常用数据传输方 ...

  3. MVVM 入门介绍

    转载自:http://www.objccn.io/issue-13-1/ 我于 2011 年在 500px 找到自己的第一份 iOS 开发工作.虽然我已经在大学里做了好几年 iOS 外包开发,但这才是 ...

  4. jdk,tomcat配置

    方法/步骤 一.安装JDK和Tomcat 1,安装JDK:直接运行jdk-7-windows-i586.exe可执行程序,默认安装即可. 备注:路径可以其他盘符,不建议路径包含中文名及特殊符号. 2. ...

  5. iOS 开发者应该知道的 ARM 结构

    http://news.cnblogs.com/n/68903/ 我在写「NEON on iPhone 入门」的时候,曾以为读者已经比较了解 iOS设备的处理器知识.然而,看过网上的一些讨论,我才发现 ...

  6. 转载 Deep learning:三(Multivariance Linear Regression练习)

    前言: 本文主要是来练习多变量线性回归问题(其实本文也就3个变量),参考资料见网页:http://openclassroom.stanford.edu/MainFolder/DocumentPage. ...

  7. HDU 1269 迷宫城堡 tarjan算法求强连通分量

    基础模板题,应用tarjan算法求有向图的强连通分量,tarjan在此处的实现方法为:使用栈储存已经访问过的点,当访问的点离开dfs的时候,判断这个点的low值是否等于它的出生日期dfn值,如果相等, ...

  8. Air打包exe

    1.用flash创建一个airtest.fla,发布目标选择为AIR.ctrl+enter会得到如下文件: 2.把flex sdk的bin中找到adl.exe,复制过来,放置到:项目目录\bin\ad ...

  9. asp 特殊字符替换

    <%Function specialstr(yourstring)find= "¿,À,Á,Â,Ã,Ä,Å,Æ,Ç,È,É,Ê,Ë,Ì,Í,Î,Ï,Ð,Ñ,Ò,Ó,Ô,Õ,Ö,Ø,Ù, ...

  10. hdu_3564_Another LIS(线段树+LIS)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3564 题意:给你N个数的位置.数i的位置为第i个数,比如 0 0 2,表示1插在第0个位置,此时数列为 ...