Advertisement
dmkozyrev

423.cpp

Jun 11th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <vector>
  4. #include <string>
  5.  
  6. const long long LIMIT = 1000000000000LL;
  7. const int WIDTH = 12;
  8.  
  9. struct Int {
  10.     long long a, b;
  11.    
  12.     Int(long long a = 0, long long b = 0) : a(a), b(b) { }
  13.    
  14.     inline Int operator + (const Int & other) {
  15.         return Int(a+other.a+(b+other.b) / LIMIT, (b+other.b) % LIMIT);
  16.     }
  17. };
  18.  
  19. std::ostream & operator << (std::ostream & os, const Int & num) {
  20.     if (num.a)
  21.         os << num.a << std::setw(WIDTH) << std::setfill('0');
  22.     return os << num.b;
  23. }
  24.  
  25. inline bool is_digit(char a, char b) {
  26.     return (a-'0') && (a-'0')*10+(b-'0') <= 33;
  27. }
  28.  
  29. int main() {
  30.     freopen("input.txt", "rt", stdin);
  31.     freopen("output.txt", "wt", stdout);
  32.    
  33.     std::string s;
  34.     std::cin >> s;
  35.    
  36.     int len = (int) s.length();
  37.    
  38.     std::vector<Int> count(1+len, Int(0, 1));
  39.    
  40.     for (int i = 2; i <= len; ++i)
  41.         count[i] = is_digit(s[i-2], s[i-1]) ? count[i-2]+count[i-1] : count[i-1];
  42.    
  43.     std::cout << count.back(); 
  44.    
  45.     return 0;  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement