-
Notifications
You must be signed in to change notification settings - Fork 0
/
W1_C3.cpp
65 lines (50 loc) · 835 Bytes
/
W1_C3.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
#include <iostream>
#include <fstream>
using namespace std;
//int tbnc(int a, int b, int c, int n);
int main()
{
ifstream ipfl;
ofstream opfl;
ipfl.open("input.txt");
opfl.open("output.txt");
int a, b, c, n;
ipfl >> a >> b >> c >> n;
//opfl << tbnc(a, b, c, n);
if (n == 0)
opfl << a;
else if (n == 1)
opfl << b;
else if (n == 2)
opfl << c;
else
{
int ary[100001];
ary[0] = a;
ary[1] = b;
ary[2] = c;
int i = 3;
while(i <= n)
{
ary[i] = ary[i - 1] + ary[i - 2] - ary[i - 3];
i++;
}
opfl << ary[n];
}
ipfl.close();
opfl.close();
return 0;
}
//int tbnc(int a, int b, int c, int n)
//{
// if (n == 0)
// return a;
// else if (n == 1)
// return b;
// else if (n == 2)
// return c;
// else if (n == 3)
// return c + b - a;
// else
// return tbnc(a, b, c, n - 1) + b - a;
//}