根据Fibnacci数翻译给的那段英文(题目),原文和密文之间相差一个Fibnacci数。
即:原文字母序号-密文字母序号=Fibnacci(注意26为一个循环节)
题目:要我们求所给数字的各位数字的和。
AC:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<climits>
#include<string>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;
#define rep(i,j,k)for(i=j;i<k;i++)
#define per(i,j,k)for(i=j;i>k;i--)
#define MS(x,y)memset(x,y,sizeof(x))
typedef long long LL;
const int INF =0x7FFFFFFF;
int main()
{
char str[100];
int i,j,k;
while(~scanf("%s",str))
{
int len=strlen(str);
int sum=0;
rep(i,0,len)
{
if(str[i]=='-')continue;
else sum+=str[i]-'0';
}
printf("%d\n",sum);
}
return 0;
}
题目:
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<algorithm>
char s[28]={'0','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
int main()
{
long long a[100];
a[0]=1;a[1]=1;
for(int i=2;i<100;i++)
a[i]=a[i-1]+a[i-2];
char c[100];
gets(c);
for(int i=0,x=0;i<strlen(c);)
{
for(int j=1;j<=26;j++)
{
if(c[i]==s[j])
{
c[i]=s[(j-a[x]%26+26)%26];
i++;x++;
break;
}
else if(c[i]==' '||c[i]==',')
{
i++;
}
}
}
printf("%s",c);
}