ACM___________________________

______________白白の屋
posts - 182, comments - 102, trackbacks - 0, articles - 0

HDOJ HDU 2672 god is a girl ACM 2672 IN HDU

Posted on 2010-08-04 12:47 MiYu 阅读(316) 评论(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= 011 };
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;
}


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理