Posted on 2010-08-04 12:47
MiYu 閱讀(347)
評論(0) 編輯 收藏 引用 所屬分類:
ACM ( 串 ) 、
ACM ( 數論 )
//MiYu原創, 轉帖請注明 : 轉載自 ______________白白の屋
題目地址 :
http://acm.hdu.edu.cn/showproblem.php?pid=2672
好吧..............我承認, 當我看這題的解題報告時, 我被征服了................
代碼如下:
//MiYu原創, 轉帖請注明 : 轉載自 ______________白白の屋
#include <iostream>
#include <string>
#include <cctype>
using namespace std;

int a[1001] =
{ 0, 1, 1 };
int main ()


{
// 第N個字母對應 第N個FIBONACI數列的第N項 ,當然,這是字母,要取模
for ( int i = 2; i < 1001; ++ i )

{
a[i] = ( a[i - 1] + a[i - 2] ) % 26;
}
string str;
while ( getline ( cin , str ) )

{
int num = 0;
for ( int i = 0; str[i]; ++i )

{
//對每個A-Z字符進行處理
if ( isupper ( str[i] ) )

{
num ++;
printf ( "%c", isupper ( str[i] + a[num] ) ? str[i] + a[num] : str[i] + a[num] - 26 );
}
else

{
printf ( "%c", str[i] );
}
}
printf("\n");
}
return 0;
}
