-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecursionTrain.cpp
168 lines (167 loc) · 2.75 KB
/
recursionTrain.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define du double
#define vi vector<int>
#define se set<int>
#define vvi vector<vector<int>>
const float N = 3.14;
// void substrings(string s , string ans)
// {
// if(s.length()==0)
// {
// cout<<ans<<endl;
// return ;
// }
// char temp = s[0];
// int ch = temp;
// string ros = s.substr(1);
// substrings(ros,ans);
// substrings(ros,ans+temp);
// substrings(ros,ans+to_string(ch));
// }
void substrings(string s , string ans)
{
if(s.length()==0)
{
cout<<ans<<endl;
return ;
}
char temp = s[0];
string ros = s.substr(1);
substrings(ros,ans);
substrings(ros,ans+temp);
}
string sameSTRINGsolve(string s) // same charectors in a word filtur out
{
if(s.length()==0)
{
return "";
}
char temp = s[0];
string ans = sameSTRINGsolve(s.substr(1));
if(temp == ans[0])
{
return ans;
}
else
{
return temp+ans;
}
}
string xEND(string s) //if words contains x then the x shift to the end of the words
{
if(s.length()==0)
{
return "";
}
char temp = s[0];
string ans = xEND(s.substr(1));
if(temp=='x')
{
return ans+temp;
}
else
{
return temp+ans;
}
return xEND(s.substr(1));
}
void pi(string s) //if word contains the pi then the pi changes to 3.14
{
if(s.length()==0)
{
return;
}
string ans ;
if(s[0]=='p'&&s[1]=='i')
{
cout<<PI;
ans = s.substr(2);
}
else
{
cout<<s[0];
ans = s.substr(1);
}
pi(ans);
}
int fibonaci(int n)
{
if(n==2)
{
return 1;
}
if(n==1)
{
return 0;
}
cout<<n-1<<" "<<n-2<<endl;
return fibonaci(n-1)+fibonaci(n-2);
}
int recurSum(int n)
{
if (n <= 1)
return n;
return n + recurSum(n - 1);
}
int digitSum(int n)
{
if(n==0)
{
return 0;
}
int sum = digitSum(n/10) + (n%10);
return sum;
}
int findSum(int A[], int N)
{
if (N <= 0)
{
return 0;
}
return (findSum(A, N - 1) + A[N - 1]);
}
void print(int n)
{
for(int i=1;i<=n;i++)
{
cout<<i<<" ";
}
cout<<endl;
}
void patprint(int n)
{
if(n==1)
{
cout<<1<<endl;return;
}
print(n);
patprint(n-1);
print(n);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll t;cin>>t;
while(t--)
{
int n;cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
// printf("%d", findSum(a, n));
// cout<<digitSum(n);
// patprint(n);
cout<<fibonaci(n);
}
return 0;
}