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

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


{
// 第N個(gè)字母對(duì)應(yīng) 第N個(gè)FIBONACI數(shù)列的第N項(xiàng) ,當(dāng)然,這是字母,要取模
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 )

{
//對(duì)每個(gè)A-Z字符進(jìn)行處理
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;
}
