凯撒密码 CH Round #57 - Story of the OI Class

题目:http://ch.ezoj.tk/contest/CH%20Round%20%2357%20-%20Story%20of%20the%20OI%20Class/凯撒密码

题解:刚开始想map,结果被出题说的卡map提醒了。

然后直觉告诉我可以hash相邻字母的距离,然后就这样做了。。。

代码:

 #include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 1000000
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 1000000007
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
int n,t,a[maxn],b[maxn],f[][];
char s[];
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();
for1(i,)
for1(j,)
f[i][j]=j>=i?j-i:-i+j;
for1(i,n)
{
scanf("%s",s);t=;
for0(j,)t=t*+f[s[j]-'a'+][s[j+]-'a'+];
a[t]=i;b[t]=s[];
}
for1(i,n)
{
scanf("%s",s);t=;
for0(j,)t=t*+f[s[j]-'a'+][s[j+]-'a'+];
printf("%d %d\n",a[t],f[s[]-'a'+][b[t]-'a'+]);
}
return ;
}
上一篇:Docker 容器入门


下一篇:angular todo