Skip to content

Commit f39d7f8

Browse files
authored
Initial commit
1 parent 420e4f3 commit f39d7f8

File tree

4 files changed

+396
-0
lines changed

4 files changed

+396
-0
lines changed

Logical-Questions/CheatingExam.cpp

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
//author @Nishant
2+
/*
3+
IAMSMARTERTHANYOU
4+
IE U
5+
ATRO
6+
MRTY
7+
SAHN
8+
M A
9+
*/
10+
11+
#include<bits/stdc++.h>
12+
using namespace std;
13+
14+
int main(){
15+
int n;
16+
cin >> n;
17+
string encoded;
18+
cin >> encoded;
19+
if(encoded.length() <= 0 || n<=0){
20+
return 0;
21+
}
22+
if(n==1){
23+
cout << encoded;
24+
return 0;
25+
}
26+
int len = (encoded.length()-1)/(n-1);
27+
if(len%2 != 0){
28+
len += 1;
29+
}
30+
char code[n][len];
31+
int k = 0;
32+
for(int i=0; i<n; i++){
33+
for(int j=0; j<len; j++){
34+
if(i==0 && j==0){
35+
code[i][i] = encoded.at(k++);
36+
}
37+
if(i==0 && j>0){
38+
if(j%2!=0){
39+
code[i][j] = encoded.at(k++);
40+
}
41+
}
42+
if(i>0 && i<n-1){
43+
code[i][j] = encoded.at(k++);
44+
}
45+
if(i==n-1){
46+
if(j%2 == 0){
47+
code[i][j] = encoded.at(k++);
48+
}
49+
}
50+
}
51+
}
52+
// for(int i=0;i<n;i++){
53+
// cout << endl;
54+
// for(int j=0;j<len;j++)
55+
// cout << code[i][j] << "\t";
56+
// }
57+
vector<char> ans;
58+
for(int j=0; j<len; j++){
59+
if(j%2==0){
60+
if(j==0){
61+
for(int i=0; i<n; i++){
62+
//if(code[i][j]!='X' && (code[i+1][j]!='X' || code[i][j+1]!='X')){
63+
//if(code[i][j]!='X'){
64+
ans.push_back(code[i][j]);
65+
//}
66+
}
67+
}else{
68+
for(int i=1; i<n; i++){
69+
//if(code[i][j]!='X'){
70+
ans.push_back(code[i][j]);
71+
//}
72+
}
73+
}
74+
}else{
75+
for(int i=n-2; i>=0; i--){
76+
//if(code[i][j]!='X'){
77+
ans.push_back(code[i][j]);
78+
//}
79+
}
80+
}
81+
}
82+
int temp = ans.size()-1;
83+
while(ans.at(temp) == 'X'){
84+
temp--;
85+
}
86+
for(int i=0; i<=temp; i++){
87+
cout << ans.at(i);
88+
}
89+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
void printPrime(int n);
5+
bool isPrime(int n);
6+
unsigned int combination(unsigned int a, unsigned int b);
7+
8+
int main(){
9+
int n;
10+
cin >> n;
11+
printPrime(n);
12+
return 0;
13+
}
14+
15+
bool isPrime(int n){
16+
if (n <= 1)
17+
return false;
18+
for (int i = 2; i < n; i++)
19+
if (n % i == 0)
20+
return false;
21+
return true;
22+
}
23+
24+
unsigned int combination(unsigned int a, unsigned int b){
25+
unsigned int x = 10;
26+
while(b >= x)
27+
x *= 10;
28+
return a * x + b;
29+
}
30+
31+
void printPrime(int n){
32+
vector<int> primes;
33+
for (int i = 2; i <= n; i++){
34+
if (isPrime(i))
35+
primes.push_back(i);
36+
}
37+
int totalN = primes.size();
38+
set<int> combo;
39+
for(int i=0; i<totalN; i++){
40+
int x = primes.at(i);
41+
for(int j=i+1; j<totalN; j++){
42+
int y = primes.at(j);
43+
int xy = combination(x, y);
44+
int yx = combination(y, x);
45+
if(isPrime(xy)){
46+
combo.insert(xy);
47+
}
48+
if(isPrime(yx)){
49+
combo.insert(yx);
50+
}
51+
}
52+
}
53+
cout << combo.size();
54+
}

Logical-Questions/PalindromeNum.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//author @Nishant
2+
3+
#include<bits/stdc++.h>
4+
using namespace std;
5+
6+
int countPalindrome(int n){
7+
int x = pow(10, (n-1)/2);
8+
return (9 * x);
9+
}
10+
11+
int main(){
12+
int n;
13+
cin >> n;
14+
int sum = 0;
15+
for(int i=1; i<=n; i++){
16+
sum += countPalindrome(i);
17+
}
18+
cout << sum;
19+
return 0;
20+
}

0 commit comments

Comments
 (0)