forked from Sahil1gupta/CheatNotes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
282 lines (250 loc) · 9.92 KB
/
index.html
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>🤩 CheatSheet for C🤩 </title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Potta+One&display=swap" rel="stylesheet" />
<link rel="stylesheet" href="style.css" />
<script src="prism.js"></script>
<link rel="stylesheet" href="prism.css" />
</head>
<body>
<nav>
<span class="logo"><img
src="https://w7.pngwing.com/pngs/592/864/png-transparent-computer-icons-icon-design-cut-copy-and-paste-taobao-clothing-promotional-copy-text-rectangle-emoticon.png"
alt="logo" /></span>
<!-- Change your heading below according to your topic and technoloy you are working with -->
<div class="content center">C++ Question_Solved CheatSheet 🥳🎉 </div>
</nav>
<!-- for html replace < this with < and > > -->
<div class="container">
<ol>
<!-- Put your code below in li section -->
<li>
Fibonacci Number
Given a number N,figure out if it is a member of fibonacci series or not.Return true if the number is memebr of
fibonacci sereis else false.<br>
Fibonacci Series is defined by the recurrence<br>
F(n) = F(n-1) + F(n-2)<br>
where F(0) = 0 and F(1) = 1<br>
<div class="accordion" id="accordionPanelsStayOpenExample">
<div class="accordion-item">
<h2 class="accordion-header" id="panelsStayOpen-headingOne">
<button class="accordion-button" type="button" data-bs-toggle="collapse"
data-bs-target="#panelsStayOpen-collapseOne" aria-expanded="true"
aria-controls="panelsStayOpen-collapseOne">
Input Format✍
</button>
</h2>
<div id="panelsStayOpen-collapseOne" class="accordion-collapse collapse show"
aria-labelledby="panelsStayOpen-headingOne">
<div class="accordion-body">
<strong>Input Format :</strong><br>
Integer N<br>
<strong>Output Format :</strong><br>
true or false<br>
<strong>Constraints :</strong> <br>
0 <= n <=10^4<br>
<strong>Sample Input 1 :</strong> <br>
5<br>
<strong>Sample Output 1 :</strong> <br>
true<br>
<strong> Sample Input 2 :</strong><br>
14
<strong>Sample Output 2 :</strong><br>
false<br>
</div>
</div>
</div>
</div>
<pre class="language-cpp"><code>
#include<iostream>
using namespace std;
bool isFib(int n){
int i=1;
int fisrtNum=0;
int secondNum=1;
if(n==0 || n==1){
return true;
}
while(i<=n){
int x= fisrtNum+secondNum;
if(x==n){
return true;
}
fisrtNum=secondNum;
secondNum=x;
i++;
}
return false;
}
int main(){
cout<<"ENTER YOUR NUMBER: "<<endl;
int x;
cin>>x;
int y= isFib(x);
cout<<y<<endl;
}
</code>
</pre>
</li>
<!-- write description below-->
<div class="accordion" id="accordionPanelsStayOpenExample">
<div class="accordion-item">
<h2 class="accordion-header" id="panelsStayOpen-headingOne">
<button class="accordion-button" type="button" data-bs-toggle="collapse"
data-bs-target="#panelsStayOpen-collapseOne" aria-expanded="true"
aria-controls="panelsStayOpen-collapseOne">
Explanation (English)
</button>
</h2>
<div id="panelsStayOpen-collapseOne" class="accordion-collapse collapse show"
aria-labelledby="panelsStayOpen-headingOne">
<div class="accordion-body">
<strong>This is the first item's accordion body.</strong> It is
shown by default, until the collapse plugin adds the appropriate
classes that we use to style each element. These classes control
the overall appearance, as well as the showing and hiding via
CSS transitions. You can modify any of this with custom CSS or
overriding our default variables. It's also worth noting that
just about any HTML can go within the
<code>.accordion-body</code>, though the transition does limit
overflow.
</div>
</div>
</div>
<!-- Put your code below in li section -->
<br>
<li>
Palindrom
Given an integer N, the task is to check whether the sum of digits of N is palindrome or not.
Time Complexity: O(logN)<br>
Auxiliary Space: O(1)<br>
<div class="accordion" id="accordionPanelsStayOpenExample">
<div class="accordion-item">
<h2 class="accordion-header" id="panelsStayOpen-headingOne">
<button class="accordion-button" type="button" data-bs-toggle="collapse"
data-bs-target="#panelsStayOpen-collapseOne" aria-expanded="true"
aria-controls="panelsStayOpen-collapseOne">
Input Format✍
</button>
</h2>
<div id="panelsStayOpen-collapseOne" class="accordion-collapse collapse show"
aria-labelledby="panelsStayOpen-headingOne">
<div class="accordion-body">
<strong>Input Format :</strong><br>
Integer N: N = 56<br>
<strong>Output Format :</strong><br>
YES or NO<br>
<strong>Explaination: </strong> <br>
Digit sum is (5 + 6) = 11, which is a palindrome.<br>
<strong>Sample Input 1 :</strong> <br>
56<br>
<strong>Sample Output 1 :</strong> <br>
YES<br>
<strong> Sample Input 2 :</strong><br>
12321
<strong>Sample Output 2 :</strong><br>
NO<br>
</div>
</div>
</div>
</div>
<pre class="language-cpp"><code>
// C++ implementation of the approach
#include <bits/stdc++.h>
using namespace std;
// Function to return the
// sum of digits of n
int digitSum(int n)
{
int sum = 0;
while (n > 0) {
sum += (n % 10);
n /= 10;
}
return sum;
}
// Function that returns true
// if n is palindrome
bool isPalindrome(int n)
{
// Find the appropriate divisor
// to extract the leading digit
int divisor = 1;
while (n / divisor >= 10)
divisor *= 10;
while (n != 0) {
int leading = n / divisor;
int trailing = n % 10;
// If first and last digit
// not same return false
if (leading != trailing)
return false;
// Removing the leading and trailing
// digit from number
n = (n % divisor) / 10;
// Reducing divisor by a factor
// of 2 as 2 digits are dropped
divisor = divisor / 100;
}
return true;
}
// Function that returns true if
// the digit sum of n is palindrome
bool isDigitSumPalindrome(int n)
{
// Sum of the digits of n
int sum = digitSum(n);
// If the digit sum is palindrome
if (isPalindrome(sum))
return true;
return false;
}
// Driver code
int main()
{
int n = 56;
if (isDigitSumPalindrome(n))
cout << "Yes";
else
cout << "No";
return 0;
}
</code>
</pre>
</li>
<!-- write description below-->
<div class="accordion" id="accordionPanelsStayOpenExample">
<div class="accordion-item">
<h2 class="accordion-header" id="panelsStayOpen-headingOne">
<button class="accordion-button" type="button" data-bs-toggle="collapse"
data-bs-target="#panelsStayOpen-collapseOne" aria-expanded="true"
aria-controls="panelsStayOpen-collapseOne">
Explanation (English)
</button>
</h2>
<div id="panelsStayOpen-collapseOne" class="accordion-collapse collapse show"
aria-labelledby="panelsStayOpen-headingOne">
<div class="accordion-body">
The first and last digits can be compared, and then the process is repeated. We require the numerical
order for the first digit. Say, 12321. The leading 1 would be obtained by multiplying this by 10,000. By
taking the mod with 10, you can get the trailing 1. Let's get this down to 232 now.
<strong> (12321 % 10000)/10 = (2321)/10 = 232</strong>
It would then be necessary to take a 100 percent reduction off of the 10,000.
</div>
</div>
</div>
</div>
</ol>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>
</body>
</html>