-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10334 - Ray Through Glasses.cpp
75 lines (61 loc) · 1.21 KB
/
10334 - Ray Through Glasses.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
string rev (string s)
{
reverse(s.begin() , s.end());
return s;
}
string add(string s1, string s2)
{
int carry = 0, x , y , sum = 0, k = 0;
string s = "" , d , a, b;
a = rev(s1);
b = rev(s2);
for(int i = 0; i < a.length(); i++)
{
if(i < b.length())
{
x = a[i] - 48;
y = b[i] - 48;
sum = carry + x + y;
k = sum % 10;
s += k + 48;
carry = 0;
if(sum > 9) carry = 1;
if(carry == 1 && i == a.length() - 1)
{
s += 49;
}
}
else
{
x = a[i] - 48;
sum = carry + x;
k = sum % 10;
s += k + 48;
carry = 0;
if(sum > 9) carry = 1;
if(carry == 1 && i == a.length() - 1)
{
s += 49;
}
}
}
return (s);
}
int main()
{
int x;
map <int , string> mp;
mp[0] = "1";
mp[1] = "2";
for(int i = 2; i <= 1000; i++)
{
mp[i] = rev(add(mp[i - 1] , mp[i - 2]));
}
while(cin >> x)
{
cout<<mp[x] <<endl;
}
}