Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C++ by Gammy ( 15 years ago )
/*
 * main.cpp
 *
 *  Created on: 08.02.2011
 *      Author: pasha
 */

#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;



class BigInteger
{
 static const int base = 1000000000;

 vector<int> digits;

 void remove_zeroes()
 {
  while (digits.size() > 1 && digits.back() == 0)
  {
   digits.pop_back();
  }
 }

public:
 BigInteger(int a) :
  digits(1, a)
 {
 }

 BigInteger& operator+=(BigInteger const & a)
 {
  for (int i = 0, rem = 0; i < (int) a.digits.size() || rem != 0; i++)
  {
   if ((int) digits.size() == i)
   {
    digits.push_back(0);
   }
   digits[i] += rem + ((int) a.digits.size() <= i ? 0 : a.digits[i]);
   rem = digits[i] / base;
   digits[i] %= base;
  }
  return *this;
 }

 friend ofstream & operator<<(ofstream & out, BigInteger const & a)
 {
  out << a.digits.back();
  for (int i = a.digits.size() - 2; i >= 0; i--)
  {
   int cur = a.digits[i];
   for (int j = base / 10; j > 0; j /= 10)
   {
    out << cur / j;
    cur %= j;
   }
  }
  return out;
 }
};

ifstream stin;
ofstream stout;
istringstream parser;

int main()
{
 stin.open("input.txt");
 stout.open("output.txt");
 string digits;
 stin >> digits;
 BigInteger prevprev(1);
 BigInteger prev(1);
 BigInteger cur(0);
 for (int i = 0; i < (int) digits.size(); i++)
 {
  digits[i] -= '0';
  cur = prev;
  if (digits[i - 1] * 10 + digits[i] <= 33 && digits[i - 1] * 10 >= 10)
  {
   cur += prevprev;
  }
  prevprev = prev;
  prev = cur;
 }
 stout << prev << '\n';
}

 

Revise this Paste

Your Name: Code Language: