題目大意:
現在題目被加密了, 給出加密後的串
hjxh dwh v vxxpde,mmo ijzr yfcz hg pbzrxdvgqij rid stl mc zspm vfvuu vb uwu spmwzh.
一直前面4個詞是give you a number, 出題人說自己只會Fibonacci...
解密這一段文字然後寫程序
大致思路:
既然出題人說自己只會Fibonacci, 腦洞一下這個提議, 注意到前幾個字母: (h, g), (j, i), (x, v)..差距依次是1, 1, 2, 3, 5, 8....於是猜想字符差距是Fibonacci數, 以26爲循環節即可
得到解密之後的題面是:give you a number,and your task is calculating the sum of each digit in the number
於是就是個無聊的求按位之和的題了, 注意n是long long 範圍當n取-2^63的時候轉正整數的long long會出錯就行了
代碼如下:
Result : Accepted Memory : 1672 KB Time : 0 ms
/*
* this code is made by Gatevin
* Problem: 1069
* Verdict: Accepted
* Submission Date: 2015-09-13 22:10:16
* Time: 0MS
* Memory: 1672KB
*/
/*
* Author: Gatevin
* Created Time: 2015/9/12 12:12:47
* File Name: Sakura_Chiyo.cpp
*/
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#include<iomanip>
using namespace std;
const double eps(1e-8);
typedef long long lint;
typedef unsigned long long ulint;
/*
* hjxh dwh v vxxpde,mmo ijzr yfcz hg pbzrxdvgqij rid stl mc zspm vfvuu vb uwu spmwzh
* give you a number
* h - g = 1
* j - i = 1
* x - v = 2
* h - e = 3
* d - y = 26 + d - y = 5
* w - o = 8
* 猜想, 解密需要將所有字符加上Fibonacci數取模26得到, 前兩項是1 1
*/
int fib[100];
int main()
{
//freopen("out.out", "w", stdout);
fib[0] = fib[1] = 1;
string s = "hjxh dwh v vxxpde,mmo ijzr yfcz hg pbzrxdvgqij rid stl mc zspm vfvuu vb uwu spmwzh";
for(int i = 2, sz = s.length(); i < sz; i++)
fib[i] = (fib[i - 1] + fib[i - 2]) % 26;
int num = 0;
for(int i = 0, sz = s.length(); i < sz; i++)
if(s[i] != ' ' && s[i] != ',') s[i] = ((s[i] - 'a') - fib[num++] + 26) % 26 + 'a';
//cout<<s<<endl;
//s = "give you a number,and your task is calculating the sum of each digit in the number";
lint n;
while(scanf("%lld", &n) != EOF)
{
ulint N;
if(n < 0)
{
N = (ulint)(-(n + 1)) + 1uLL;
}
else N = n;
ulint ans = 0;
while(N)
{
ans += N % 10uLL;
N /= 10uLL;
}
printf("%llu\n", ans);
}
return 0;
}