close

好吧... 我承認... 這題超簡單... 熱身題...

對拉!我懶XDD 當練習vector和iomanip吧... (說好的不用STL呢...)

#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;

typedef vector<double> dvec;

int main()
{

   double mb=0, fb=1.0;
   double mb_n, fb_n;
   double temp;
   double year=0;
   dvec arr;
   dvec m_result;
   dvec f_result;

   /*input initail value*/
   m_result.push_back(mb);
   f_result.push_back(fb);

   /*input each value*/
   while(cin>>temp&&temp!=-1)
   {
       arr.push_back(temp);
       if(year<temp) year=temp;
   }

   /*count the number of bees until the max number*/
   for(int i=0; i!=year; ++i)
   {
       mb_n=mb+fb;
       fb_n=mb+1;
       mb=mb_n;
       fb=fb_n;
       m_result.push_back(mb);
       f_result.push_back(fb);
   }

   /*cout the number without precison*/
   cout.precision(0);
   dvec::iterator p;
   for(p=arr.begin(); p!=arr.end(); ++p)
   {
       cout<< fixed <<m_result[*p]<<" "<<m_result[*p]+f_result[*p]<<endl;
   }

   return 0;
}


其實聰明人會發現... 這題就是印出費伯那西數列n-1及n...

人笨就要多寫點 我實在沒辦法阿(攤手)

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 milksleisure 的頭像
    milksleisure

    Milk's Leisure

    milksleisure 發表在 痞客邦 留言(0) 人氣()